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

Side by Side Diff: chrome/browser/chromeos/extensions/file_browser_event_router.cc

Issue 10352004: gdata: Implement periodic file system update checks. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix compile error in mock_gdata_file_system.h Created 8 years, 7 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
OLDNEW
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/extensions/file_browser_event_router.h" 5 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 extension_id, 159 extension_id,
160 is_remote_watch)); 160 is_remote_watch));
161 161
162 if (watch->Watch(watch_path, delegate_.get())) 162 if (watch->Watch(watch_path, delegate_.get()))
163 file_watchers_[watch_path] = watch.release(); 163 file_watchers_[watch_path] = watch.release();
164 else 164 else
165 return false; 165 return false;
166 } else { 166 } else {
167 iter->second->AddExtension(extension_id); 167 iter->second->AddExtension(extension_id);
168 } 168 }
169 if (is_remote_watch) {
170 gdata::GDataFileSystem* file_system = GetFileSystem();
171 if (file_system)
172 file_system->AddFileWatch(watch_path);
173 }
169 return true; 174 return true;
170 } 175 }
171 176
172 void FileBrowserEventRouter::RemoveFileWatch( 177 void FileBrowserEventRouter::RemoveFileWatch(
173 const FilePath& local_path, 178 const FilePath& local_path,
174 const std::string& extension_id) { 179 const std::string& extension_id) {
175 base::AutoLock lock(lock_); 180 base::AutoLock lock(lock_);
176 FilePath watch_path = local_path; 181 FilePath watch_path = local_path;
182 bool is_remote_watch = false;
177 // Tweak watch path for remote sources - we need to drop leading /special 183 // Tweak watch path for remote sources - we need to drop leading /special
178 // directory from there in order to be able to pair these events with 184 // directory from there in order to be able to pair these events with
179 // their change notifications. 185 // their change notifications.
180 if (gdata::util::GetSpecialRemoteRootPath().IsParent(watch_path)) { 186 if (gdata::util::GetSpecialRemoteRootPath().IsParent(watch_path)) {
181 watch_path = gdata::util::ExtractGDataPath(watch_path); 187 watch_path = gdata::util::ExtractGDataPath(watch_path);
188 is_remote_watch = true;
182 } 189 }
183 WatcherMap::iterator iter = file_watchers_.find(watch_path); 190 WatcherMap::iterator iter = file_watchers_.find(watch_path);
184 if (iter == file_watchers_.end()) 191 if (iter == file_watchers_.end())
185 return; 192 return;
186 // Remove the renderer process for this watch. 193 // Remove the renderer process for this watch.
187 iter->second->RemoveExtension(extension_id); 194 iter->second->RemoveExtension(extension_id);
188 if (iter->second->GetRefCount() == 0) { 195 if (iter->second->GetRefCount() == 0) {
189 delete iter->second; 196 delete iter->second;
190 file_watchers_.erase(iter); 197 file_watchers_.erase(iter);
191 } 198 }
199 if (is_remote_watch) {
200 gdata::GDataFileSystem* file_system = GetFileSystem();
201 if (file_system)
202 file_system->RemoveFileWatch(watch_path);
203 }
192 } 204 }
193 205
194 void FileBrowserEventRouter::DiskChanged( 206 void FileBrowserEventRouter::DiskChanged(
195 DiskMountManagerEventType event, 207 DiskMountManagerEventType event,
196 const DiskMountManager::Disk* disk) { 208 const DiskMountManager::Disk* disk) {
197 // Disregard hidden devices. 209 // Disregard hidden devices.
198 if (disk->is_hidden()) 210 if (disk->is_hidden())
199 return; 211 return;
200 if (event == chromeos::disks::MOUNT_DISK_ADDED) { 212 if (event == chromeos::disks::MOUNT_DISK_ADDED) {
201 OnDiskAdded(disk); 213 OnDiskAdded(disk);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 notifications_->ManageNotificationsOnMountCompleted( 260 notifications_->ManageNotificationsOnMountCompleted(
249 disk->system_path_prefix(), disk->drive_label(), disk->is_parent(), 261 disk->system_path_prefix(), disk->drive_label(), disk->is_parent(),
250 error_code == chromeos::MOUNT_ERROR_NONE, 262 error_code == chromeos::MOUNT_ERROR_NONE,
251 error_code == chromeos::MOUNT_ERROR_UNSUPORTED_FILESYSTEM); 263 error_code == chromeos::MOUNT_ERROR_UNSUPORTED_FILESYSTEM);
252 } else if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { 264 } else if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) {
253 // Clear the "mounted" state for archive files in gdata cache 265 // Clear the "mounted" state for archive files in gdata cache
254 // when mounting failed or unmounting succeeded. 266 // when mounting failed or unmounting succeeded.
255 if ((event_type == DiskMountManager::MOUNTING) != 267 if ((event_type == DiskMountManager::MOUNTING) !=
256 (error_code == chromeos::MOUNT_ERROR_NONE)) { 268 (error_code == chromeos::MOUNT_ERROR_NONE)) {
257 FilePath source_path(mount_info.source_path); 269 FilePath source_path(mount_info.source_path);
258 gdata::GDataSystemService* system_service = 270 gdata::GDataFileSystem* file_system = GetFileSystem();
259 gdata::GDataSystemServiceFactory::GetForProfile(profile_);
260 gdata::GDataFileSystem* file_system =
261 system_service ? system_service->file_system() : NULL;
262 if (file_system && file_system->IsUnderGDataCacheDirectory(source_path)) 271 if (file_system && file_system->IsUnderGDataCacheDirectory(source_path))
263 file_system->SetMountedState(source_path, false, 272 file_system->SetMountedState(source_path, false,
264 gdata::SetMountedStateCallback()); 273 gdata::SetMountedStateCallback());
265 } 274 }
266 } 275 }
267 } 276 }
268 277
269 void FileBrowserEventRouter::OnProgressUpdate( 278 void FileBrowserEventRouter::OnProgressUpdate(
270 const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) { 279 const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) {
271 scoped_ptr<ListValue> event_list( 280 scoped_ptr<ListValue> event_list(
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 unsigned int 603 unsigned int
595 FileBrowserEventRouter::FileWatcherExtensions::GetRefCount() const { 604 FileBrowserEventRouter::FileWatcherExtensions::GetRefCount() const {
596 return ref_count_; 605 return ref_count_;
597 } 606 }
598 607
599 const FilePath& 608 const FilePath&
600 FileBrowserEventRouter::FileWatcherExtensions::GetVirtualPath() const { 609 FileBrowserEventRouter::FileWatcherExtensions::GetVirtualPath() const {
601 return virtual_path_; 610 return virtual_path_;
602 } 611 }
603 612
613 gdata::GDataFileSystem* FileBrowserEventRouter::GetFileSystem() const {
614 gdata::GDataSystemService* system_service =
615 gdata::GDataSystemServiceFactory::GetForProfile(profile_);
616 return (system_service ? system_service->file_system() : NULL);
617 }
618
604 bool FileBrowserEventRouter::FileWatcherExtensions::Watch 619 bool FileBrowserEventRouter::FileWatcherExtensions::Watch
605 (const FilePath& path, FileWatcherDelegate* delegate) { 620 (const FilePath& path, FileWatcherDelegate* delegate) {
606 if (is_remote_file_system_) 621 if (is_remote_file_system_)
607 return true; 622 return true;
608 623
609 return file_watcher_->Watch(path, delegate); 624 return file_watcher_->Watch(path, delegate);
610 } 625 }
611 626
612 // static 627 // static
613 scoped_refptr<FileBrowserEventRouter> 628 scoped_refptr<FileBrowserEventRouter>
(...skipping 22 matching lines...) Expand all
636 return scoped_refptr<RefcountedProfileKeyedService>( 651 return scoped_refptr<RefcountedProfileKeyedService>(
637 new FileBrowserEventRouter(profile)); 652 new FileBrowserEventRouter(profile));
638 } 653 }
639 654
640 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { 655 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() {
641 // Explicitly and always allow this router in guest login mode. see 656 // Explicitly and always allow this router in guest login mode. see
642 // chrome/browser/profiles/profile_keyed_base_factory.h comment 657 // chrome/browser/profiles/profile_keyed_base_factory.h comment
643 // for the details. 658 // for the details.
644 return true; 659 return true;
645 } 660 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698