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

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

Issue 7243012: Change many extension event routers to not be singletons and to be more profile-aware. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 DictionaryValue* result = new DictionaryValue(); 48 DictionaryValue* result = new DictionaryValue();
49 result->SetString("mountPath", disk->mount_path()); 49 result->SetString("mountPath", disk->mount_path());
50 result->SetString("devicePath", disk->device_path()); 50 result->SetString("devicePath", disk->device_path());
51 result->SetString("label", disk->device_label()); 51 result->SetString("label", disk->device_label());
52 result->SetString("deviceType", DeviceTypeToString(disk->device_type())); 52 result->SetString("deviceType", DeviceTypeToString(disk->device_type()));
53 result->SetInteger("totalSizeKB", disk->total_size() / 1024); 53 result->SetInteger("totalSizeKB", disk->total_size() / 1024);
54 result->SetBoolean("readOnly", disk->is_read_only()); 54 result->SetBoolean("readOnly", disk->is_read_only());
55 return result; 55 return result;
56 } 56 }
57 57
58 ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter() 58 ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter(
59 Profile* profile)
59 : delegate_(new ExtensionFileBrowserEventRouter::FileWatcherDelegate()), 60 : delegate_(new ExtensionFileBrowserEventRouter::FileWatcherDelegate()),
60 profile_(NULL) { 61 profile_(profile) {
61 } 62 }
62 63
63 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() { 64 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() {
64 DCHECK(file_watchers_.empty()); 65 DCHECK(file_watchers_.empty());
65 STLDeleteValues(&file_watchers_); 66 STLDeleteValues(&file_watchers_);
66 67
67 if (!profile_) 68 if (!profile_)
68 return; 69 return;
69 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) 70 if (!chromeos::CrosLibrary::Get()->EnsureLoaded())
70 return; 71 return;
71 chromeos::MountLibrary* lib = 72 chromeos::MountLibrary* lib =
72 chromeos::CrosLibrary::Get()->GetMountLibrary(); 73 chromeos::CrosLibrary::Get()->GetMountLibrary();
73 lib->RemoveObserver(this); 74 lib->RemoveObserver(this);
74 profile_ = NULL;
75 } 75 }
76 76
77 // static 77 void ExtensionFileBrowserEventRouter::Init() {
78 ExtensionFileBrowserEventRouter* 78 if (!profile_)
asargent_no_longer_on_chrome 2011/06/23 22:18:38 Should we have NOTREACHED() or CHECK(false) here i
Yoyo Zhou 2011/06/24 17:21:38 Sure.
79 ExtensionFileBrowserEventRouter::GetInstance() {
80 return Singleton<ExtensionFileBrowserEventRouter>::get();
81 }
82
83 void ExtensionFileBrowserEventRouter::ObserveFileSystemEvents(
84 Profile* profile) {
85 if (!profile)
86 return; 79 return;
87 profile_ = profile;
88 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) 80 if (!chromeos::CrosLibrary::Get()->EnsureLoaded())
89 return; 81 return;
90 if (chromeos::UserManager::Get()->user_is_logged_in()) { 82 if (chromeos::UserManager::Get()->user_is_logged_in()) {
91 chromeos::MountLibrary* lib = 83 chromeos::MountLibrary* lib =
92 chromeos::CrosLibrary::Get()->GetMountLibrary(); 84 chromeos::CrosLibrary::Get()->GetMountLibrary();
93 lib->RemoveObserver(this); 85 lib->RemoveObserver(this);
94 lib->AddObserver(this); 86 lib->AddObserver(this);
95 lib->RequestMountInfoRefresh(); 87 lib->RequestMountInfoRefresh();
96 } 88 }
97 } 89 }
(...skipping 28 matching lines...) Expand all
126 if (iter == file_watchers_.end()) 118 if (iter == file_watchers_.end())
127 return; 119 return;
128 // Remove the renderer process for this watch. 120 // Remove the renderer process for this watch.
129 iter->second->extensions.erase(extension_id); 121 iter->second->extensions.erase(extension_id);
130 if (iter->second->extensions.empty()) { 122 if (iter->second->extensions.empty()) {
131 delete iter->second; 123 delete iter->second;
132 file_watchers_.erase(iter); 124 file_watchers_.erase(iter);
133 } 125 }
134 } 126 }
135 127
136 void ExtensionFileBrowserEventRouter::StopObservingFileSystemEvents() {
137 if (!profile_)
138 return;
139 if (!chromeos::CrosLibrary::Get()->EnsureLoaded())
140 return;
141 chromeos::MountLibrary* lib =
142 chromeos::CrosLibrary::Get()->GetMountLibrary();
143 lib->RemoveObserver(this);
144 profile_ = NULL;
145 }
146
147 void ExtensionFileBrowserEventRouter::DiskChanged( 128 void ExtensionFileBrowserEventRouter::DiskChanged(
148 chromeos::MountLibraryEventType event, 129 chromeos::MountLibraryEventType event,
149 const chromeos::MountLibrary::Disk* disk) { 130 const chromeos::MountLibrary::Disk* disk) {
150 if (event == chromeos::MOUNT_DISK_ADDED) { 131 if (event == chromeos::MOUNT_DISK_ADDED) {
151 OnDiskAdded(disk); 132 OnDiskAdded(disk);
152 } else if (event == chromeos::MOUNT_DISK_REMOVED) { 133 } else if (event == chromeos::MOUNT_DISK_REMOVED) {
153 OnDiskRemoved(disk); 134 OnDiskRemoved(disk);
154 } else if (event == chromeos::MOUNT_DISK_CHANGED) { 135 } else if (event == chromeos::MOUNT_DISK_CHANGED) {
155 OnDiskChanged(disk); 136 OnDiskChanged(disk);
156 } 137 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 local_path, 364 local_path,
384 true)); // got_error 365 true)); // got_error
385 } 366 }
386 367
387 void 368 void
388 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( 369 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread(
389 const FilePath& local_path, bool got_error) { 370 const FilePath& local_path, bool got_error) {
390 ExtensionFileBrowserEventRouter::GetInstance()->HandleFileWatchNotification( 371 ExtensionFileBrowserEventRouter::GetInstance()->HandleFileWatchNotification(
391 local_path, got_error); 372 local_path, got_error);
392 } 373 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698