Chromium Code Reviews| 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_file_system.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 2120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2131 lock_.AssertAcquired(); | 2131 lock_.AssertAcquired(); |
| 2132 // Find directory element within the cached file system snapshot. | 2132 // Find directory element within the cached file system snapshot. |
| 2133 ReadOnlyFindEntryDelegate find_delegate; | 2133 ReadOnlyFindEntryDelegate find_delegate; |
| 2134 root_->FindEntryByPath(file_path, &find_delegate); | 2134 root_->FindEntryByPath(file_path, &find_delegate); |
| 2135 return find_delegate.entry(); | 2135 return find_delegate.entry(); |
| 2136 } | 2136 } |
| 2137 | 2137 |
| 2138 void GDataFileSystem::GetCacheState(const std::string& resource_id, | 2138 void GDataFileSystem::GetCacheState(const std::string& resource_id, |
| 2139 const std::string& md5, | 2139 const std::string& md5, |
| 2140 const GetCacheStateCallback& callback) { | 2140 const GetCacheStateCallback& callback) { |
| 2141 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 2141 // Always post a task to the UI thread to call GetCacheStateOnUIThread even if |
|
Ben Chan
2012/04/30 04:37:21
Another way to fix this issue is to have GetCacheS
satorux1
2012/04/30 05:52:06
Sounds good. Please add
DCHECK(BrowserThread::Cur
Ben Chan
2012/04/30 06:18:58
Done.
| |
| 2142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2142 // GetCacheState is called on the UI thread. This ensures that, regardless of |
| 2143 const bool posted = BrowserThread::PostTask( | 2143 // whether GDataFileSystem is locked or not, GDataFileSystem is unlocked when |
| 2144 BrowserThread::UI, | 2144 // GetCacheStateOnUIThread is called. |
| 2145 FROM_HERE, | 2145 const bool posted = BrowserThread::PostTask( |
| 2146 base::Bind(&GDataFileSystem::GetCacheStateOnUIThread, | 2146 BrowserThread::UI, |
| 2147 ui_weak_ptr_, | 2147 FROM_HERE, |
| 2148 resource_id, | 2148 base::Bind(&GDataFileSystem::GetCacheStateOnUIThread, |
| 2149 md5, | 2149 ui_weak_ptr_, |
| 2150 base::Bind(&RelayGetCacheStateCallback, | 2150 resource_id, |
| 2151 base::MessageLoopProxy::current(), | 2151 md5, |
| 2152 callback))); | 2152 base::Bind(&RelayGetCacheStateCallback, |
| 2153 DCHECK(posted); | 2153 base::MessageLoopProxy::current(), |
| 2154 return; | 2154 callback))); |
| 2155 } | 2155 DCHECK(posted); |
| 2156 | |
| 2157 GetCacheStateOnUIThread(resource_id, md5, callback); | |
| 2158 } | 2156 } |
| 2159 | 2157 |
| 2160 void GDataFileSystem::GetCacheStateOnUIThread( | 2158 void GDataFileSystem::GetCacheStateOnUIThread( |
| 2161 const std::string& resource_id, | 2159 const std::string& resource_id, |
| 2162 const std::string& md5, | 2160 const std::string& md5, |
| 2163 const GetCacheStateCallback& callback) { | 2161 const GetCacheStateCallback& callback) { |
| 2164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2165 | 2163 |
| 2166 // This method originates from GDataFile::GetCacheState, which already locks, | 2164 InitializeCacheIfNecessary(); |
| 2167 // so we shouldn't lock here. | |
| 2168 UnsafeInitializeCacheIfNecessary(); | |
| 2169 | 2165 |
| 2170 base::PlatformFileError* error = | 2166 base::PlatformFileError* error = |
| 2171 new base::PlatformFileError(base::PLATFORM_FILE_OK); | 2167 new base::PlatformFileError(base::PLATFORM_FILE_OK); |
| 2172 int* cache_state = new int(GDataFile::CACHE_STATE_NONE); | 2168 int* cache_state = new int(GDataFile::CACHE_STATE_NONE); |
| 2173 | 2169 |
| 2174 // GetCacheStateOnIOThreadPool won't do file IO, but post it to the thread | 2170 // GetCacheStateOnIOThreadPool won't do file IO, but post it to the thread |
| 2175 // pool, as it must be performed after the cache is initialized. | 2171 // pool, as it must be performed after the cache is initialized. |
| 2176 PostBlockingPoolSequencedTaskAndReply( | 2172 PostBlockingPoolSequencedTaskAndReply( |
| 2177 FROM_HERE, | 2173 FROM_HERE, |
| 2178 base::Bind(&GDataFileSystem::GetCacheStateOnIOThreadPool, | 2174 base::Bind(&GDataFileSystem::GetCacheStateOnIOThreadPool, |
| (...skipping 2227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4406 bool* has_enough_space = new bool(false); | 4402 bool* has_enough_space = new bool(false); |
| 4407 PostBlockingPoolSequencedTask( | 4403 PostBlockingPoolSequencedTask( |
| 4408 FROM_HERE, | 4404 FROM_HERE, |
| 4409 base::Bind(&GDataFileSystem::FreeDiskSpaceIfNeeded, | 4405 base::Bind(&GDataFileSystem::FreeDiskSpaceIfNeeded, |
| 4410 base::Unretained(this), | 4406 base::Unretained(this), |
| 4411 base::Owned(has_enough_space))); | 4407 base::Owned(has_enough_space))); |
| 4412 } | 4408 } |
| 4413 | 4409 |
| 4414 //============= GDataFileSystem: internal helper functions ===================== | 4410 //============= GDataFileSystem: internal helper functions ===================== |
| 4415 | 4411 |
| 4416 void GDataFileSystem::UnsafeInitializeCacheIfNecessary() { | 4412 void GDataFileSystem::UnsafeInitializeCacheIfNecessary() { |
|
Ben Chan
2012/04/30 04:37:21
We could remove UnsafeInitializeCacheIfNecessary a
satorux1
2012/04/30 05:52:06
Sounds great. Please remove it.
Ben Chan
2012/04/30 06:18:58
Done.
| |
| 4417 lock_.AssertAcquired(); | 4413 lock_.AssertAcquired(); |
| 4418 | 4414 |
| 4419 if (cache_initialization_started_) { | 4415 if (cache_initialization_started_) { |
| 4420 // Cache initialization is either in progress or has completed. | 4416 // Cache initialization is either in progress or has completed. |
| 4421 return; | 4417 return; |
| 4422 } | 4418 } |
| 4423 | 4419 |
| 4424 // Need to initialize cache. | 4420 // Need to initialize cache. |
| 4425 | 4421 |
| 4426 cache_initialization_started_ = true; | 4422 cache_initialization_started_ = true; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4581 pref_registrar_->Init(profile_->GetPrefs()); | 4577 pref_registrar_->Init(profile_->GetPrefs()); |
| 4582 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 4578 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
| 4583 } | 4579 } |
| 4584 | 4580 |
| 4585 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 4581 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
| 4586 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 4582 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
| 4587 global_free_disk_getter_for_testing = getter; | 4583 global_free_disk_getter_for_testing = getter; |
| 4588 } | 4584 } |
| 4589 | 4585 |
| 4590 } // namespace gdata | 4586 } // namespace gdata |
| OLD | NEW |