[Bbs2ch-cvs 204] [186] 明示的なオブジェクトの開放と abone 関連メソッドの外部オブジェクト化

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2007年 8月 5日 (日) 01:51:11 JST


Revision: 186
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=bbs2ch&view=rev&rev=186
Author:   flyson
Date:     2007-08-05 01:51:11 +0900 (Sun, 05 Aug 2007)

Log Message:
-----------
明示的なオブジェクトの開放と abone 関連メソッドの外部オブジェクト化

Modified Paths:
--------------
    trunk/bbs2chreader/components/nsBbs2chService.js

Modified: trunk/bbs2chreader/components/nsBbs2chService.js
===================================================================
--- trunk/bbs2chreader/components/nsBbs2chService.js	2007-07-28 14:42:26 UTC (rev 185)
+++ trunk/bbs2chreader/components/nsBbs2chService.js	2007-08-04 16:51:11 UTC (rev 186)
@@ -122,6 +122,55 @@
 
 
 
+
+function b2rAbone(aBbs2chService){
+	this._init(aBbs2chService);
+}
+
+b2rAbone.prototype = {
+
+	_init: function(aBbs2chService){
+		this._bbs2chService = aBbs2chService;
+		this.refreshAboneData();
+	},
+
+	shouldAbone: function(aName, aMail, aID, aMsg){
+		function checkFunc(aElement, aIndex, aArray){
+			return this.indexOf(aElement) != -1;
+		}
+		if(this._aboneData["name"].some(checkFunc, aName)) return true;
+		if(this._aboneData["mail"].some(checkFunc, aMail)) return true;
+		if(this._aboneData["id"].some(checkFunc, aID)) return true;
+		if(this._aboneData["word"].some(checkFunc, aMsg)) return true;
+
+		return false;
+	},
+
+	refreshAboneData: function(){
+		this._aboneData = new Array();
+		this._aboneData["name"] = this._loadNgFile("NGnames.txt");
+		this._aboneData["mail"] = this._loadNgFile("NGaddrs.txt");
+		this._aboneData["id"] = this._loadNgFile("NGid.txt");
+		this._aboneData["word"] = this._loadNgFile("NGwords.txt");
+	},
+
+	_loadNgFile: function(aNgFilePath){
+		var ngFile = this._bbs2chService.getDataDir();
+		ngFile.appendRelativePath(aNgFilePath);
+		if(!ngFile.exists()) return new Array();
+
+		var contentLine = this._bbs2chService.readFileLine(ngFile.path, {});
+		var resultArray = new Array();
+			// 空白行は読み込まない
+		for(var i=0; i<contentLine.length; i++){
+			if(contentLine[i]) resultArray.push(contentLine[i]);
+		}
+		return resultArray;
+	}
+
+}
+
+
 function nsBbs2chService(){
 		// getBoardType で利用する例外的な URL のリスト( 2ch だけど板じゃない URL)
 	this._exURLs = new Array(
@@ -136,6 +185,7 @@
 	this.__unicodeConverter = null;
 	this.__ioService = null;
 	this._globalHistory = null;
+	this._abone = null;
 	this._pref = null;
 	this._prefDefault = null;
 	this._userAgent = null;
@@ -234,9 +284,21 @@
 
 	_delayInit: function(){
 		this._globalHistory = new b2rGlobalHistory(this);
+		this._abone = new b2rAbone(this);
 		this._maruAutoAuth();
 	},
 
+	_shutdown: function(){
+		this.__unicodeConverter = null;
+		this.__ioService = null;
+		this._globalHistory = null;
+		this._abone = null;
+		this._pref = null;
+		this._prefDefault = null;
+		this._userAgent = null;
+		this._serverURL = null;
+	},
+
 	toSJIS: function(aString){
 		this._unicodeConverter.charset = "Shift_JIS";
 		return this._unicodeConverter.ConvertFromUnicode(aString);
@@ -575,39 +637,11 @@
 
 
 	shouldAbone: function(aName, aMail, aID, aMsg){
-		if(!this._aboneData) this.refreshAboneData();
-
-		function checkFunc(aElement, aIndex, aArray){
-			return this.indexOf(aElement) != -1;
-		}
-		if(this._aboneData["name"].some(checkFunc, aName)) return true;
-		if(this._aboneData["mail"].some(checkFunc, aMail)) return true;
-		if(this._aboneData["id"].some(checkFunc, aID)) return true;
-		if(this._aboneData["word"].some(checkFunc, aMsg)) return true;
-
-		return false;
+		return this._abone.shouldAbone(aName, aMail, aID, aMsg);
 	},
 
 	refreshAboneData: function(){
-		function loadNgFile(aService, aNgFilePath){
-			var ngFile = aService.getDataDir();
-			ngFile.appendRelativePath(aNgFilePath);
-			if(!ngFile.exists()) return new Array();
-
-			var contentLine = aService.readFileLine(ngFile.path, {});
-			var resultArray = new Array();
-				// 空白行は読み込まない
-			for(var i=0; i<contentLine.length; i++){
-				if(contentLine[i]) resultArray.push(contentLine[i]);
-			}
-			return resultArray;
-		}
-
-		this._aboneData = new Array();
-		this._aboneData["name"] = loadNgFile(this, "NGnames.txt");
-		this._aboneData["mail"] = loadNgFile(this, "NGaddrs.txt");
-		this._aboneData["id"] = loadNgFile(this, "NGid.txt");
-		this._aboneData["word"] = loadNgFile(this, "NGwords.txt");
+		this._abone.refreshAboneData();
 	},
 
 
@@ -746,12 +780,20 @@
 	observe: function(aSubject, aTopic, aData){
 		var os = Components.classes["@mozilla.org/observer-service;1"]
 					.getService(Components.interfaces.nsIObserverService);
-		if(aTopic == "app-startup"){
-			os.addObserver(this, "final-ui-startup", false);
-			dump("nsBbs2chService\n");
-		}else if(aTopic == "final-ui-startup"){
-			os.removeObserver(this, "final-ui-startup");
-			this._delayInit();
+		switch(aTopic){
+			case "app-startup":
+				os.addObserver(this, "final-ui-startup", false);
+				os.addObserver(this, "xpcom-shutdown", false);
+				dump("nsBbs2chService\n");
+				break;
+			case "final-ui-startup":
+				os.removeObserver(this, "final-ui-startup");
+				this._delayInit();
+				break;
+			case "xpcom-shutdown":
+				this._shutdown();
+				os.removeObserver(this, "xpcom-shutdown");
+				break;
 		}
 	},
 




bbs2ch-cvs メーリングリストの案内
Back to archive index