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

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

Issue 215024: Fix appcache_service and request_context referencing. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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/chrome_thread.h" 13 #include "chrome/browser/chrome_thread.h"
13 #include "chrome/common/chrome_constants.h" 14 #include "chrome/common/chrome_constants.h"
14 #include "webkit/appcache/appcache_service.h" 15 #include "webkit/appcache/appcache_service.h"
15 16
16 // An AppCacheService subclass used by the chrome. There is an instance 17 // An AppCacheService subclass used by the chrome. There is an instance
17 // associated with each Profile. This derivation adds refcounting semantics 18 // associated with each Profile. This derivation adds refcounting semantics
18 // since a profile has multiple URLRequestContexts which refer to the same 19 // since a profile has multiple URLRequestContexts which refer to the same
19 // object, and those URLRequestContexts are refcounted independently of the 20 // object, and those URLRequestContexts are refcounted independently of the
20 // owning profile. 21 // owning profile.
21 // 22 //
22 // 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
23 // except for the ctor and the init method which are expected to be called on 24 // except for the ctor and the init method which are expected to be called on
24 // the UI thread. 25 // the UI thread.
25 class ChromeAppCacheService 26 class ChromeAppCacheService
26 : public base::RefCountedThreadSafe<ChromeAppCacheService>, 27 : public base::RefCountedThreadSafe<ChromeAppCacheService>,
27 public appcache::AppCacheService { 28 public appcache::AppCacheService {
28 public: 29 public:
29 30
30 explicit ChromeAppCacheService() 31 explicit ChromeAppCacheService()
31 : was_initialized_with_io_thread_(false) { 32 : is_initialized_(false), was_initialized_with_io_thread_(false) {
32 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
33 } 33 }
34 34
35 bool is_initialized() const { return is_initialized_; }
36
35 void InitializeOnUIThread(const FilePath& data_directory, 37 void InitializeOnUIThread(const FilePath& data_directory,
36 URLRequestContext* request_context,
37 bool is_incognito) { 38 bool is_incognito) {
38 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 39 DCHECK(!is_initialized_);
39 set_request_context(request_context); 40 is_initialized_ = true;
40 41
41 // Some test cases run without an IO thread. 42 // The I/O thread may be NULL during testing.
42 MessageLoop* io_thread = ChromeThread::GetMessageLoop(ChromeThread::IO); 43 base::Thread* io_thread = g_browser_process->io_thread();
43 if (io_thread) { 44 if (io_thread) {
44 was_initialized_with_io_thread_ = true; 45 was_initialized_with_io_thread_ = true;
45 io_thread->PostTask(FROM_HERE, 46 io_thread->message_loop()->PostTask(FROM_HERE,
46 NewRunnableMethod(this, &ChromeAppCacheService::InitializeOnIOThread, 47 NewRunnableMethod(this, &ChromeAppCacheService::InitializeOnIOThread,
47 data_directory, is_incognito)); 48 data_directory, is_incognito));
48 } 49 }
49 } 50 }
50 51
51 private: 52 private:
52 friend class base::RefCountedThreadSafe<ChromeAppCacheService>; 53 friend class base::RefCountedThreadSafe<ChromeAppCacheService>;
53 54
54 virtual ~ChromeAppCacheService() { 55 virtual ~ChromeAppCacheService() {
55 DCHECK(!was_initialized_with_io_thread_ || 56 DCHECK(!was_initialized_with_io_thread_ ||
56 ChromeThread::CurrentlyOn(ChromeThread::IO)); 57 ChromeThread::CurrentlyOn(ChromeThread::IO));
57 } 58 }
58 59
59 void InitializeOnIOThread(const FilePath& data_directory, 60 void InitializeOnIOThread(const FilePath& data_directory,
60 bool is_incognito) { 61 bool is_incognito) {
61 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 62 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
62 Initialize(is_incognito ? FilePath() 63 Initialize(is_incognito ? FilePath()
63 : data_directory.Append(chrome::kAppCacheDirname)); 64 : data_directory.Append(chrome::kAppCacheDirname));
64 } 65 }
65 66
67 bool is_initialized_;
66 bool was_initialized_with_io_thread_; 68 bool was_initialized_with_io_thread_;
67 }; 69 };
68 70
69 #endif // CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_ 71 #endif // CHROME_COMMON_APPCACHE_CHROME_APPCACHE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698