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

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

Issue 12729002: Add a unified observer to replace NetworkManagerObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix mobile_activator_unittest Created 7 years, 9 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/file_util.h" 8 #include "base/file_util.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/prefs/public/pref_change_registrar.h" 12 #include "base/prefs/public/pref_change_registrar.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/chromeos/cros/cros_library.h" 15 #include "chrome/browser/chromeos/cros/cros_library.h"
16 #include "chrome/browser/chromeos/drive/drive_cache.h" 16 #include "chrome/browser/chromeos/drive/drive_cache.h"
17 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" 17 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h"
18 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" 18 #include "chrome/browser/chromeos/drive/drive_file_system_util.h"
19 #include "chrome/browser/chromeos/drive/drive_system_service.h" 19 #include "chrome/browser/chromeos/drive/drive_system_service.h"
20 #include "chrome/browser/chromeos/extensions/file_browser_notifications.h" 20 #include "chrome/browser/chromeos/extensions/file_browser_notifications.h"
21 #include "chrome/browser/chromeos/extensions/file_manager_util.h" 21 #include "chrome/browser/chromeos/extensions/file_manager_util.h"
22 #include "chrome/browser/chromeos/login/base_login_display_host.h" 22 #include "chrome/browser/chromeos/login/base_login_display_host.h"
23 #include "chrome/browser/chromeos/login/screen_locker.h" 23 #include "chrome/browser/chromeos/login/screen_locker.h"
24 #include "chrome/browser/chromeos/login/user_manager.h" 24 #include "chrome/browser/chromeos/login/user_manager.h"
25 #include "chrome/browser/chromeos/net/connectivity_state_helper.h"
25 #include "chrome/browser/extensions/event_names.h" 26 #include "chrome/browser/extensions/event_names.h"
26 #include "chrome/browser/extensions/event_router.h" 27 #include "chrome/browser/extensions/event_router.h"
27 #include "chrome/browser/extensions/extension_service.h" 28 #include "chrome/browser/extensions/extension_service.h"
28 #include "chrome/browser/extensions/extension_system.h" 29 #include "chrome/browser/extensions/extension_system.h"
29 #include "chrome/browser/google_apis/drive_service_interface.h" 30 #include "chrome/browser/google_apis/drive_service_interface.h"
30 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/common/chrome_notification_types.h" 32 #include "chrome/common/chrome_notification_types.h"
32 #include "chrome/common/pref_names.h" 33 #include "chrome/common/pref_names.h"
33 #include "chromeos/dbus/cros_disks_client.h" 34 #include "chromeos/dbus/cros_disks_client.h"
34 #include "chromeos/dbus/dbus_thread_manager.h" 35 #include "chromeos/dbus/dbus_thread_manager.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 268
268 DriveSystemService* system_service = 269 DriveSystemService* system_service =
269 DriveSystemServiceFactory::FindForProfileRegardlessOfStates(profile_); 270 DriveSystemServiceFactory::FindForProfileRegardlessOfStates(profile_);
270 if (system_service) { 271 if (system_service) {
271 system_service->file_system()->RemoveObserver(this); 272 system_service->file_system()->RemoveObserver(this);
272 system_service->drive_service()->RemoveObserver(this); 273 system_service->drive_service()->RemoveObserver(this);
273 } 274 }
274 275
275 chromeos::CrosLibrary* cros_library = chromeos::CrosLibrary::Get(); 276 chromeos::CrosLibrary* cros_library = chromeos::CrosLibrary::Get();
276 if (cros_library) { 277 if (cros_library) {
277 chromeos::NetworkLibrary* network_library = 278 chromeos::ConnectivityStateHelper::Get()->
278 cros_library->GetNetworkLibrary(); 279 RemoveNetworkManagerObserver(this);
279 if (network_library)
280 network_library->RemoveNetworkManagerObserver(this);
281 } 280 }
282 281
283 profile_ = NULL; 282 profile_ = NULL;
284 } 283 }
285 284
286 void FileBrowserEventRouter::ObserveFileSystemEvents() { 285 void FileBrowserEventRouter::ObserveFileSystemEvents() {
287 if (!profile_) { 286 if (!profile_) {
288 NOTREACHED(); 287 NOTREACHED();
289 return; 288 return;
290 } 289 }
291 if (!chromeos::UserManager::Get()->IsUserLoggedIn()) 290 if (!chromeos::UserManager::Get()->IsUserLoggedIn())
292 return; 291 return;
293 292
294 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); 293 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance();
295 if (disk_mount_manager) { 294 if (disk_mount_manager) {
296 disk_mount_manager->RemoveObserver(this); 295 disk_mount_manager->RemoveObserver(this);
297 disk_mount_manager->AddObserver(this); 296 disk_mount_manager->AddObserver(this);
298 disk_mount_manager->RequestMountInfoRefresh(); 297 disk_mount_manager->RequestMountInfoRefresh();
299 } 298 }
300 299
301 DriveSystemService* system_service = 300 DriveSystemService* system_service =
302 DriveSystemServiceFactory::GetForProfileRegardlessOfStates(profile_); 301 DriveSystemServiceFactory::GetForProfileRegardlessOfStates(profile_);
303 if (system_service) { 302 if (system_service) {
304 system_service->drive_service()->AddObserver(this); 303 system_service->drive_service()->AddObserver(this);
305 system_service->file_system()->AddObserver(this); 304 system_service->file_system()->AddObserver(this);
306 } 305 }
307 306
308 chromeos::CrosLibrary* cros_library = chromeos::CrosLibrary::Get(); 307 chromeos::CrosLibrary* cros_library = chromeos::CrosLibrary::Get();
309 if (cros_library) { 308 if (cros_library) {
tbarzic 2013/03/11 23:12:31 Do we still have to check that cros_library is pre
gauravsh 2013/03/12 00:30:25 That's what I figured - this pattern is used in ma
310 chromeos::NetworkLibrary* network_library = 309 chromeos::ConnectivityStateHelper::Get()->AddNetworkManagerObserver(this);
311 cros_library->GetNetworkLibrary();
312 if (network_library)
313 network_library->AddNetworkManagerObserver(this);
314 } 310 }
315 311
316 suspend_state_delegate_.reset(new SuspendStateDelegateImpl()); 312 suspend_state_delegate_.reset(new SuspendStateDelegateImpl());
317 313
318 pref_change_registrar_->Init(profile_->GetPrefs()); 314 pref_change_registrar_->Init(profile_->GetPrefs());
319 315
320 pref_change_registrar_->Add( 316 pref_change_registrar_->Add(
321 prefs::kExternalStorageDisabled, 317 prefs::kExternalStorageDisabled,
322 base::Bind(&FileBrowserEventRouter::OnExternalStorageDisabledChanged, 318 base::Bind(&FileBrowserEventRouter::OnExternalStorageDisabledChanged,
323 base::Unretained(this))); 319 base::Unretained(this)));
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 DiskMountManager::FormatEvent event, 522 DiskMountManager::FormatEvent event,
527 chromeos::FormatError error_code, 523 chromeos::FormatError error_code,
528 const std::string& device_path) { 524 const std::string& device_path) {
529 if (event == DiskMountManager::FORMAT_STARTED) { 525 if (event == DiskMountManager::FORMAT_STARTED) {
530 OnFormatStarted(device_path, error_code == chromeos::FORMAT_ERROR_NONE); 526 OnFormatStarted(device_path, error_code == chromeos::FORMAT_ERROR_NONE);
531 } else if (event == DiskMountManager::FORMAT_COMPLETED) { 527 } else if (event == DiskMountManager::FORMAT_COMPLETED) {
532 OnFormatCompleted(device_path, error_code == chromeos::FORMAT_ERROR_NONE); 528 OnFormatCompleted(device_path, error_code == chromeos::FORMAT_ERROR_NONE);
533 } 529 }
534 } 530 }
535 531
536 void FileBrowserEventRouter::OnNetworkManagerChanged( 532 void FileBrowserEventRouter::NetworkManagerChanged() {
537 chromeos::NetworkLibrary* network_library) {
538 if (!profile_ || 533 if (!profile_ ||
539 !extensions::ExtensionSystem::Get(profile_)->event_router()) { 534 !extensions::ExtensionSystem::Get(profile_)->event_router()) {
540 NOTREACHED(); 535 NOTREACHED();
541 return; 536 return;
542 } 537 }
543 scoped_ptr<extensions::Event> event(new extensions::Event( 538 scoped_ptr<extensions::Event> event(new extensions::Event(
544 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, 539 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged,
545 scoped_ptr<ListValue>(new ListValue()))); 540 scoped_ptr<ListValue>(new ListValue())));
546 extensions::ExtensionSystem::Get(profile_)->event_router()-> 541 extensions::ExtensionSystem::Get(profile_)->event_router()->
547 BroadcastEvent(event.Pass()); 542 BroadcastEvent(event.Pass());
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 } 946 }
952 947
953 bool FileBrowserEventRouter::FileWatcherExtensions::Watch( 948 bool FileBrowserEventRouter::FileWatcherExtensions::Watch(
954 const base::FilePath& path, 949 const base::FilePath& path,
955 const base::FilePathWatcher::Callback& callback) { 950 const base::FilePathWatcher::Callback& callback) {
956 if (is_remote_file_system_) 951 if (is_remote_file_system_)
957 return true; 952 return true;
958 953
959 return file_watcher_->Watch(path, false, callback); 954 return file_watcher_->Watch(path, false, callback);
960 } 955 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698