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

Side by Side Diff: chrome/browser/media_galleries/media_galleries_scan_result_dialog_controller.cc

Issue 148093011: Abstract media galleries context menu code and use it in scan result dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Header too Created 6 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_galleries/media_galleries_scan_result_dialog_cont roller.h" 5 #include "chrome/browser/media_galleries/media_galleries_scan_result_dialog_cont roller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <list> 8 #include <list>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/media_galleries/media_file_system_registry.h" 15 #include "chrome/browser/media_galleries/media_file_system_registry.h"
16 #include "chrome/browser/media_galleries/media_galleries_histograms.h" 16 #include "chrome/browser/media_galleries/media_galleries_histograms.h"
17 #include "chrome/browser/media_galleries/media_gallery_context_menu.h"
17 #include "chrome/browser/platform_util.h" 18 #include "chrome/browser/platform_util.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/storage_monitor/storage_info.h" 20 #include "chrome/browser/storage_monitor/storage_info.h"
20 #include "chrome/browser/storage_monitor/storage_monitor.h" 21 #include "chrome/browser/storage_monitor/storage_monitor.h"
21 #include "chrome/common/extensions/permissions/media_galleries_permission.h" 22 #include "chrome/common/extensions/permissions/media_galleries_permission.h"
22 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
23 #include "extensions/common/extension.h" 24 #include "extensions/common/extension.h"
24 #include "extensions/common/permissions/permissions_data.h" 25 #include "extensions/common/permissions/permissions_data.h"
25 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
26 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #endif // USE_AURA 59 #endif // USE_AURA
59 preferences_ = 60 preferences_ =
60 g_browser_process->media_file_system_registry()->GetPreferences( 61 g_browser_process->media_file_system_registry()->GetPreferences(
61 GetProfile()); 62 GetProfile());
62 // Passing unretained pointer is safe, since the dialog controller 63 // Passing unretained pointer is safe, since the dialog controller
63 // is self-deleting, and so won't be deleted until it can be shown 64 // is self-deleting, and so won't be deleted until it can be shown
64 // and then closed. 65 // and then closed.
65 preferences_->EnsureInitialized(base::Bind( 66 preferences_->EnsureInitialized(base::Bind(
66 &MediaGalleriesScanResultDialogController::OnPreferencesInitialized, 67 &MediaGalleriesScanResultDialogController::OnPreferencesInitialized,
67 base::Unretained(this))); 68 base::Unretained(this)));
69
70 // Unretained is safe because |this| owns |context_menu_|.
71 context_menu_.reset(new MediaGalleryContextMenu(base::Bind(
72 &MediaGalleriesScanResultDialogController::DidForgetGallery,
73 base::Unretained(this))));
68 } 74 }
69 75
70 MediaGalleriesScanResultDialogController:: 76 MediaGalleriesScanResultDialogController::
71 MediaGalleriesScanResultDialogController( 77 MediaGalleriesScanResultDialogController(
72 const extensions::Extension& extension, 78 const extensions::Extension& extension,
73 MediaGalleriesPreferences* preferences, 79 MediaGalleriesPreferences* preferences,
74 const CreateDialogCallback& create_dialog_callback, 80 const CreateDialogCallback& create_dialog_callback,
75 const base::Closure& on_finish) 81 const base::Closure& on_finish)
76 : web_contents_(NULL), 82 : web_contents_(NULL),
77 extension_(&extension), 83 extension_(&extension),
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 186 }
181 187
182 on_finish_.Run(); 188 on_finish_.Run();
183 delete this; 189 delete this;
184 } 190 }
185 191
186 content::WebContents* MediaGalleriesScanResultDialogController::web_contents() { 192 content::WebContents* MediaGalleriesScanResultDialogController::web_contents() {
187 return web_contents_; 193 return web_contents_;
188 } 194 }
189 195
196 ui::MenuModel* MediaGalleriesScanResultDialogController::GetContextMenu(
197 MediaGalleryPrefId id) {
198 context_menu_->set_pref_id(id);
199 return context_menu_.get();
200 }
201
190 void MediaGalleriesScanResultDialogController::OnPreferencesInitialized() { 202 void MediaGalleriesScanResultDialogController::OnPreferencesInitialized() {
191 preferences_->AddGalleryChangeObserver(this); 203 preferences_->AddGalleryChangeObserver(this);
192 StorageMonitor::GetInstance()->AddObserver(this); 204 StorageMonitor::GetInstance()->AddObserver(this);
193 UpdateFromPreferences(); 205 UpdateFromPreferences();
194 206
195 // TODO(vandebo): Remove the conditional after the cocoa version is done. 207 // TODO(vandebo): Remove the conditional after the cocoa version is done.
196 if (!create_dialog_callback_.is_null()) 208 if (!create_dialog_callback_.is_null())
197 dialog_.reset(create_dialog_callback_.Run(this)); 209 dialog_.reset(create_dialog_callback_.Run(this));
198 } 210 }
199 211
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 322
311 void MediaGalleriesScanResultDialogController::OnGalleryInfoUpdated( 323 void MediaGalleriesScanResultDialogController::OnGalleryInfoUpdated(
312 MediaGalleriesPreferences* /* prefs */, 324 MediaGalleriesPreferences* /* prefs */,
313 MediaGalleryPrefId pref_id) { 325 MediaGalleryPrefId pref_id) {
314 OnPreferenceUpdate(extension_->id(), pref_id); 326 OnPreferenceUpdate(extension_->id(), pref_id);
315 } 327 }
316 328
317 // MediaGalleriesScanResultDialog --------------------------------------------- 329 // MediaGalleriesScanResultDialog ---------------------------------------------
318 330
319 MediaGalleriesScanResultDialog::~MediaGalleriesScanResultDialog() {} 331 MediaGalleriesScanResultDialog::~MediaGalleriesScanResultDialog() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698