Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: chrome/common/appcache/chrome_appcache_service.h

Issue 258008: Move initialization of ChromeURLRequestContexts to the IO thread. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync again, just in case Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_ 5 #ifndef CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_
6 #define CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_ 6 #define CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_
7 7
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/ref_counted.h" 10 #include "base/ref_counted.h"
11 #include "base/task.h" 11 #include "base/task.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chrome_thread.h" 13 #include "chrome/browser/chrome_thread.h"
14 #include "chrome/common/chrome_constants.h" 14 #include "chrome/common/chrome_constants.h"
15 #include "webkit/appcache/appcache_service.h" 15 #include "webkit/appcache/appcache_service.h"
16 16
17 // An AppCacheService subclass used by the chrome. There is an instance 17 // An AppCacheService subclass used by the chrome. There is an instance
18 // associated with each Profile. This derivation adds refcounting semantics 18 // associated with each Profile. This derivation adds refcounting semantics
19 // since a profile has multiple URLRequestContexts which refer to the same 19 // since a profile has multiple URLRequestContexts which refer to the same
20 // object, and those URLRequestContexts are refcounted independently of the 20 // object, and those URLRequestContexts are refcounted independently of the
21 // owning profile. 21 // owning profile.
22 // 22 //
23 // All methods, including the dtor, are expected to be called on the IO thread 23 // All methods, including the dtor, are expected to be called on the IO thread.
24 // except for the ctor and the init method which are expected to be called on
25 // the UI thread.
26 class ChromeAppCacheService 24 class ChromeAppCacheService
27 : public base::RefCountedThreadSafe<ChromeAppCacheService>, 25 : public base::RefCounted<ChromeAppCacheService>,
28 public appcache::AppCacheService { 26 public appcache::AppCacheService {
29 public: 27 public:
30 28
31 explicit ChromeAppCacheService() 29 ChromeAppCacheService(const FilePath& data_directory,
32 : is_initialized_(false), was_initialized_with_io_thread_(false) { 30 bool is_incognito) {
33 }
34
35 bool is_initialized() const { return is_initialized_; }
36
37 void InitializeOnUIThread(const FilePath& data_directory,
38 bool is_incognito) {
39 DCHECK(!is_initialized_);
40 is_initialized_ = true;
41
42 // The I/O thread may be NULL during testing.
43 base::Thread* io_thread = g_browser_process->io_thread();
44 if (io_thread) {
45 was_initialized_with_io_thread_ = true;
46 io_thread->message_loop()->PostTask(FROM_HERE,
47 NewRunnableMethod(this, &ChromeAppCacheService::InitializeOnIOThread,
48 data_directory, is_incognito));
49 }
50 }
51
52 private:
53 friend class base::RefCountedThreadSafe<ChromeAppCacheService>;
54
55 virtual ~ChromeAppCacheService() {
56 DCHECK(!was_initialized_with_io_thread_ ||
57 ChromeThread::CurrentlyOn(ChromeThread::IO));
58 }
59
60 void InitializeOnIOThread(const FilePath& data_directory,
61 bool is_incognito) {
62 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
63 Initialize(is_incognito ? FilePath() 31 Initialize(is_incognito ? FilePath()
64 : data_directory.Append(chrome::kAppCacheDirname)); 32 : data_directory.Append(chrome::kAppCacheDirname));
65 } 33 }
34 private:
35 friend class base::RefCounted<ChromeAppCacheService>;
66 36
67 bool is_initialized_; 37 virtual ~ChromeAppCacheService() {
68 bool was_initialized_with_io_thread_; 38 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
39 }
69 }; 40 };
70 41
71 #endif // CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_ 42 #endif // CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/common/appcache/appcache_dispatcher_host.cc ('k') | chrome/common/chrome_plugin_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698