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

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: Fixing up tests 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<chrome::RemovableStorageNotifications::StorageInfo>
vandebo (ex-Chrome) 2013/01/24 19:19:10 You don't need chrome:: here (already in the chrom
Greg Billock 2013/01/24 20:46:03 Done.
32 base::SystemMonitor::Get()->GetAttachedRemovableStorage(); 33 removable_storages = chrome::RemovableStorageNotifications::GetInstance()->
34 GetAttachedStorage();
33 for (size_t i = 0; i < removable_storages.size(); ++i) { 35 for (size_t i = 0; i < removable_storages.size(); ++i) {
34 if (removable_storages[i].device_id == device_id) 36 if (removable_storages[i].device_id == device_id)
35 return true; 37 return true;
36 } 38 }
37 return false; 39 return false;
38 } 40 }
39 41
40 } // namespace 42 } // namespace
41 43
42 MediaGalleriesDialogController::MediaGalleriesDialogController( 44 MediaGalleriesDialogController::MediaGalleriesDialogController(
43 content::WebContents* web_contents, 45 content::WebContents* web_contents,
44 const Extension& extension, 46 const Extension& extension,
45 const base::Closure& on_finish) 47 const base::Closure& on_finish)
46 : web_contents_(web_contents), 48 : web_contents_(web_contents),
47 extension_(&extension), 49 extension_(&extension),
48 on_finish_(on_finish) { 50 on_finish_(on_finish) {
49 MediaFileSystemRegistry* registry = 51 MediaFileSystemRegistry* registry =
50 g_browser_process->media_file_system_registry(); 52 g_browser_process->media_file_system_registry();
51 preferences_ = registry->GetPreferences( 53 preferences_ = registry->GetPreferences(
52 Profile::FromBrowserContext(web_contents->GetBrowserContext())); 54 Profile::FromBrowserContext(web_contents->GetBrowserContext()));
53 InitializePermissions(); 55 InitializePermissions();
54 56
55 dialog_.reset(MediaGalleriesDialog::Create(this)); 57 dialog_.reset(MediaGalleriesDialog::Create(this));
56 58
57 base::SystemMonitor* monitor = base::SystemMonitor::Get(); 59 RemovableStorageNotifications* notifications =
58 if (monitor) 60 RemovableStorageNotifications::GetInstance();
59 monitor->AddDevicesChangedObserver(this); 61 if (notifications)
62 notifications->AddObserver(this);
60 } 63 }
61 64
62 MediaGalleriesDialogController::MediaGalleriesDialogController() 65 MediaGalleriesDialogController::MediaGalleriesDialogController()
63 : web_contents_(NULL), 66 : web_contents_(NULL),
64 extension_(NULL), 67 extension_(NULL),
65 preferences_(NULL) {} 68 preferences_(NULL) {}
66 69
67 MediaGalleriesDialogController::~MediaGalleriesDialogController() { 70 MediaGalleriesDialogController::~MediaGalleriesDialogController() {
68 base::SystemMonitor* monitor = base::SystemMonitor::Get(); 71 RemovableStorageNotifications* notifications =
69 if (monitor) 72 RemovableStorageNotifications::GetInstance();
70 monitor->RemoveDevicesChangedObserver(this); 73 if (notifications)
74 notifications->RemoveObserver(this);
71 75
72 if (select_folder_dialog_.get()) 76 if (select_folder_dialog_.get())
73 select_folder_dialog_->ListenerDestroyed(); 77 select_folder_dialog_->ListenerDestroyed();
74 } 78 }
75 79
76 // static 80 // static
77 string16 MediaGalleriesDialogController::GetGalleryDisplayName( 81 string16 MediaGalleriesDialogController::GetGalleryDisplayName(
78 const MediaGalleryPrefInfo& gallery) { 82 const MediaGalleryPrefInfo& gallery) {
79 string16 name = gallery.display_name; 83 string16 name = gallery.display_name;
80 if (IsAttachedDevice(gallery.device_id)) { 84 if (IsAttachedDevice(gallery.device_id)) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 return; 201 return;
198 } 202 }
199 } 203 }
200 204
201 // Lastly, add it to |new_galleries_|. 205 // Lastly, add it to |new_galleries_|.
202 new_galleries_.push_back(GalleryPermission(gallery, true)); 206 new_galleries_.push_back(GalleryPermission(gallery, true));
203 dialog_->UpdateGallery(&new_galleries_.back().pref_info, true); 207 dialog_->UpdateGallery(&new_galleries_.back().pref_info, true);
204 } 208 }
205 209
206 void MediaGalleriesDialogController::OnRemovableStorageAttached( 210 void MediaGalleriesDialogController::OnRemovableStorageAttached(
207 const std::string& id, 211 const RemovableStorageNotifications::StorageInfo& info) {
208 const string16& /*name*/, 212 UpdateGalleryOnDeviceEvent(info.device_id, true /* attached */);
209 const FilePath::StringType& /*location*/) {
210 UpdateGalleryOnDeviceEvent(id, true /* attached */);
211 } 213 }
212 214
213 void MediaGalleriesDialogController::OnRemovableStorageDetached( 215 void MediaGalleriesDialogController::OnRemovableStorageDetached(
214 const std::string& id) { 216 const RemovableStorageNotifications::StorageInfo& info) {
215 UpdateGalleryOnDeviceEvent(id, false /* detached */); 217 UpdateGalleryOnDeviceEvent(info.device_id, false /* detached */);
216 } 218 }
217 219
218 void MediaGalleriesDialogController::InitializePermissions() { 220 void MediaGalleriesDialogController::InitializePermissions() {
219 const MediaGalleriesPrefInfoMap& galleries = preferences_->known_galleries(); 221 const MediaGalleriesPrefInfoMap& galleries = preferences_->known_galleries();
220 for (MediaGalleriesPrefInfoMap::const_iterator iter = galleries.begin(); 222 for (MediaGalleriesPrefInfoMap::const_iterator iter = galleries.begin();
221 iter != galleries.end(); 223 iter != galleries.end();
222 ++iter) { 224 ++iter) {
223 const MediaGalleryPrefInfo& gallery = iter->second; 225 const MediaGalleryPrefInfo& gallery = iter->second;
224 if (gallery.type == MediaGalleryPrefInfo::kBlackListed) 226 if (gallery.type == MediaGalleryPrefInfo::kBlackListed)
225 continue; 227 continue;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 282
281 if (gallery) 283 if (gallery)
282 dialog_->UpdateGallery(&gallery->pref_info, gallery->allowed); 284 dialog_->UpdateGallery(&gallery->pref_info, gallery->allowed);
283 } 285 }
284 286
285 // MediaGalleries dialog ------------------------------------------------------- 287 // MediaGalleries dialog -------------------------------------------------------
286 288
287 MediaGalleriesDialog::~MediaGalleriesDialog() {} 289 MediaGalleriesDialog::~MediaGalleriesDialog() {}
288 290
289 } // namespace chrome 291 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698