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

Side by Side Diff: chrome/browser/media_gallery/media_galleries_dialog_controller.cc

Issue 11573048: [Media Galleries] Move RemovableStorageInfo notifications to chrome namespace (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Typedef, init observer Created 7 years, 11 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) 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/media_gallery/media_galleries_dialog_controller.h" 5 #include "chrome/browser/media_gallery/media_galleries_dialog_controller.h"
6 6
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/media_gallery/media_file_system_registry.h" 10 #include "chrome/browser/media_gallery/media_file_system_registry.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/system_monitor/media_storage_util.h" 12 #include "chrome/browser/system_monitor/media_storage_util.h"
13 #include "chrome/browser/system_monitor/removable_storage_notifications.h"
13 #include "chrome/browser/ui/chrome_select_file_policy.h" 14 #include "chrome/browser/ui/chrome_select_file_policy.h"
14 #include "chrome/common/chrome_paths.h" 15 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_view.h" 18 #include "content/public/browser/web_contents_view.h"
18 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
19 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
20 21
21 using extensions::Extension; 22 using extensions::Extension;
22 23
23 namespace chrome { 24 namespace chrome {
24 25
25 namespace { 26 namespace {
26 27
27 bool IsAttachedDevice(const std::string& device_id) { 28 bool IsAttachedDevice(const std::string& device_id) {
28 if (!MediaStorageUtil::IsRemovableDevice(device_id)) 29 if (!MediaStorageUtil::IsRemovableDevice(device_id))
29 return false; 30 return false;
30 31
31 std::vector<base::SystemMonitor::RemovableStorageInfo> removable_storages = 32 std::vector<RemovableStorageNotifications::StorageInfo> removable_storages =
32 base::SystemMonitor::Get()->GetAttachedRemovableStorage(); 33 RemovableStorageNotifications::GetInstance()->GetAttachedStorage();
33 for (size_t i = 0; i < removable_storages.size(); ++i) { 34 for (size_t i = 0; i < removable_storages.size(); ++i) {
34 if (removable_storages[i].device_id == device_id) 35 if (removable_storages[i].device_id == device_id)
35 return true; 36 return true;
36 } 37 }
37 return false; 38 return false;
38 } 39 }
39 40
40 } // namespace 41 } // namespace
41 42
42 MediaGalleriesDialogController::MediaGalleriesDialogController( 43 MediaGalleriesDialogController::MediaGalleriesDialogController(
43 content::WebContents* web_contents, 44 content::WebContents* web_contents,
44 const Extension& extension, 45 const Extension& extension,
45 const base::Closure& on_finish) 46 const base::Closure& on_finish)
46 : web_contents_(web_contents), 47 : web_contents_(web_contents),
47 extension_(&extension), 48 extension_(&extension),
48 on_finish_(on_finish) { 49 on_finish_(on_finish) {
49 MediaFileSystemRegistry* registry = 50 MediaFileSystemRegistry* registry =
50 g_browser_process->media_file_system_registry(); 51 g_browser_process->media_file_system_registry();
51 preferences_ = registry->GetPreferences( 52 preferences_ = registry->GetPreferences(
52 Profile::FromBrowserContext(web_contents->GetBrowserContext())); 53 Profile::FromBrowserContext(web_contents->GetBrowserContext()));
53 InitializePermissions(); 54 InitializePermissions();
54 55
55 dialog_.reset(MediaGalleriesDialog::Create(this)); 56 dialog_.reset(MediaGalleriesDialog::Create(this));
56 57
57 base::SystemMonitor* monitor = base::SystemMonitor::Get(); 58 RemovableStorageNotifications* notifications =
58 if (monitor) 59 RemovableStorageNotifications::GetInstance();
59 monitor->AddDevicesChangedObserver(this); 60 if (notifications)
61 notifications->AddObserver(this);
60 } 62 }
61 63
62 MediaGalleriesDialogController::MediaGalleriesDialogController() 64 MediaGalleriesDialogController::MediaGalleriesDialogController()
63 : web_contents_(NULL), 65 : web_contents_(NULL),
64 extension_(NULL), 66 extension_(NULL),
65 preferences_(NULL) {} 67 preferences_(NULL) {}
66 68
67 MediaGalleriesDialogController::~MediaGalleriesDialogController() { 69 MediaGalleriesDialogController::~MediaGalleriesDialogController() {
68 base::SystemMonitor* monitor = base::SystemMonitor::Get(); 70 RemovableStorageNotifications* notifications =
69 if (monitor) 71 RemovableStorageNotifications::GetInstance();
70 monitor->RemoveDevicesChangedObserver(this); 72 if (notifications)
73 notifications->RemoveObserver(this);
71 74
72 if (select_folder_dialog_.get()) 75 if (select_folder_dialog_.get())
73 select_folder_dialog_->ListenerDestroyed(); 76 select_folder_dialog_->ListenerDestroyed();
74 } 77 }
75 78
76 // static 79 // static
77 string16 MediaGalleriesDialogController::GetGalleryDisplayName( 80 string16 MediaGalleriesDialogController::GetGalleryDisplayName(
78 const MediaGalleryPrefInfo& gallery) { 81 const MediaGalleryPrefInfo& gallery) {
79 string16 name = gallery.display_name; 82 string16 name = gallery.display_name;
80 if (IsAttachedDevice(gallery.device_id)) { 83 if (IsAttachedDevice(gallery.device_id)) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 return; 200 return;
198 } 201 }
199 } 202 }
200 203
201 // Lastly, add it to |new_galleries_|. 204 // Lastly, add it to |new_galleries_|.
202 new_galleries_.push_back(GalleryPermission(gallery, true)); 205 new_galleries_.push_back(GalleryPermission(gallery, true));
203 dialog_->UpdateGallery(&new_galleries_.back().pref_info, true); 206 dialog_->UpdateGallery(&new_galleries_.back().pref_info, true);
204 } 207 }
205 208
206 void MediaGalleriesDialogController::OnRemovableStorageAttached( 209 void MediaGalleriesDialogController::OnRemovableStorageAttached(
207 const std::string& id, 210 const RemovableStorageNotifications::StorageInfo& info) {
208 const string16& /*name*/, 211 UpdateGalleryOnDeviceEvent(info.device_id, true /* attached */);
209 const FilePath::StringType& /*location*/) {
210 UpdateGalleryOnDeviceEvent(id, true /* attached */);
211 } 212 }
212 213
213 void MediaGalleriesDialogController::OnRemovableStorageDetached( 214 void MediaGalleriesDialogController::OnRemovableStorageDetached(
214 const std::string& id) { 215 const RemovableStorageNotifications::StorageInfo& info) {
215 UpdateGalleryOnDeviceEvent(id, false /* detached */); 216 UpdateGalleryOnDeviceEvent(info.device_id, false /* detached */);
216 } 217 }
217 218
218 void MediaGalleriesDialogController::InitializePermissions() { 219 void MediaGalleriesDialogController::InitializePermissions() {
219 const MediaGalleriesPrefInfoMap& galleries = preferences_->known_galleries(); 220 const MediaGalleriesPrefInfoMap& galleries = preferences_->known_galleries();
220 for (MediaGalleriesPrefInfoMap::const_iterator iter = galleries.begin(); 221 for (MediaGalleriesPrefInfoMap::const_iterator iter = galleries.begin();
221 iter != galleries.end(); 222 iter != galleries.end();
222 ++iter) { 223 ++iter) {
223 const MediaGalleryPrefInfo& gallery = iter->second; 224 const MediaGalleryPrefInfo& gallery = iter->second;
224 if (gallery.type == MediaGalleryPrefInfo::kBlackListed) 225 if (gallery.type == MediaGalleryPrefInfo::kBlackListed)
225 continue; 226 continue;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 281
281 if (gallery) 282 if (gallery)
282 dialog_->UpdateGallery(&gallery->pref_info, gallery->allowed); 283 dialog_->UpdateGallery(&gallery->pref_info, gallery->allowed);
283 } 284 }
284 285
285 // MediaGalleries dialog ------------------------------------------------------- 286 // MediaGalleries dialog -------------------------------------------------------
286 287
287 MediaGalleriesDialog::~MediaGalleriesDialog() {} 288 MediaGalleriesDialog::~MediaGalleriesDialog() {}
288 289
289 } // namespace chrome 290 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698