OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" | 10 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 namespace { | 32 namespace { |
33 | 33 |
34 // Used in test to setup system service. | 34 // Used in test to setup system service. |
35 DocumentsServiceInterface* g_test_documents_service = NULL; | 35 DocumentsServiceInterface* g_test_documents_service = NULL; |
36 const std::string* g_test_cache_root = NULL; | 36 const std::string* g_test_cache_root = NULL; |
37 | 37 |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 GDataSystemService::GDataSystemService(Profile* profile) | 40 GDataSystemService::GDataSystemService(Profile* profile) |
41 : profile_(profile), | 41 : profile_(profile), |
42 cache_(NULL) { | 42 cache_(NULL), |
| 43 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
44 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); | 45 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); |
45 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( | 46 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( |
46 blocking_pool->GetSequenceToken()); | 47 blocking_pool->GetSequenceToken()); |
47 } | 48 } |
48 | 49 |
49 GDataSystemService::~GDataSystemService() { | 50 GDataSystemService::~GDataSystemService() { |
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
51 cache_->DestroyOnUIThread(); | 52 cache_->DestroyOnUIThread(); |
52 } | 53 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // Shut down the member objects in the reverse order of creation. | 97 // Shut down the member objects in the reverse order of creation. |
97 contacts_service_.reset(); | 98 contacts_service_.reset(); |
98 sync_client_.reset(); | 99 sync_client_.reset(); |
99 download_observer_.reset(); | 100 download_observer_.reset(); |
100 file_system_.reset(); | 101 file_system_.reset(); |
101 webapps_registry_.reset(); | 102 webapps_registry_.reset(); |
102 uploader_.reset(); | 103 uploader_.reset(); |
103 documents_service_.reset(); | 104 documents_service_.reset(); |
104 } | 105 } |
105 | 106 |
| 107 void GDataSystemService::ClearCache( |
| 108 const base::Callback<void(bool)>& callback) { |
| 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 110 |
| 111 RemoveDriveMountPoint(); |
| 112 docs_service()->CancelAll(); |
| 113 cache_->ClearAllOnUIThread( |
| 114 base::Bind(&GDataSystemService::AddBackDriveMountPoint, |
| 115 weak_ptr_factory_.GetWeakPtr(), |
| 116 callback)); |
| 117 } |
| 118 |
| 119 void GDataSystemService::AddBackDriveMountPoint( |
| 120 const base::Callback<void(bool)>& callback, |
| 121 GDataFileError error, |
| 122 const FilePath& file_path) { |
| 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 124 |
| 125 AddDriveMountPoint(); |
| 126 |
| 127 if (!callback.is_null()) |
| 128 callback.Run(error == GDATA_FILE_OK); |
| 129 } |
| 130 |
106 void GDataSystemService::AddDriveMountPoint() { | 131 void GDataSystemService::AddDriveMountPoint() { |
107 if (!gdata::util::IsGDataAvailable(profile_)) | 132 if (!gdata::util::IsGDataAvailable(profile_)) |
108 return; | 133 return; |
109 | 134 |
110 const FilePath mount_point = gdata::util::GetGDataMountPointPath(); | 135 const FilePath mount_point = gdata::util::GetGDataMountPointPath(); |
111 fileapi::ExternalFileSystemMountPointProvider* provider = | 136 fileapi::ExternalFileSystemMountPointProvider* provider = |
112 BrowserContext::GetFileSystemContext(profile_)->external_provider(); | 137 BrowserContext::GetFileSystemContext(profile_)->external_provider(); |
113 if (provider && !provider->HasMountPoint(mount_point)) { | 138 if (provider && !provider->HasMountPoint(mount_point)) { |
114 provider->AddRemoteMountPoint( | 139 provider->AddRemoteMountPoint( |
115 mount_point, | 140 mount_point, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 g_test_cache_root ? FilePath(*g_test_cache_root) : | 209 g_test_cache_root ? FilePath(*g_test_cache_root) : |
185 GDataCache::GetCacheRootPath(profile); | 210 GDataCache::GetCacheRootPath(profile); |
186 delete g_test_cache_root; | 211 delete g_test_cache_root; |
187 g_test_cache_root = NULL; | 212 g_test_cache_root = NULL; |
188 | 213 |
189 service->Initialize(documents_service, cache_root); | 214 service->Initialize(documents_service, cache_root); |
190 return service; | 215 return service; |
191 } | 216 } |
192 | 217 |
193 } // namespace gdata | 218 } // namespace gdata |
OLD | NEW |