| OLD | NEW |
| 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/ui/webui/options/media_galleries_handler.h" | 5 #include "chrome/browser/ui/webui/options/media_galleries_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 { "manageGalleriesButton", IDS_MEDIA_GALLERY_MANAGE_BUTTON }, | 40 { "manageGalleriesButton", IDS_MEDIA_GALLERY_MANAGE_BUTTON }, |
| 41 { "addNewGalleryButton", IDS_MEDIA_GALLERY_ADD_NEW_BUTTON }, | 41 { "addNewGalleryButton", IDS_MEDIA_GALLERY_ADD_NEW_BUTTON }, |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 RegisterStrings(values, resources, arraysize(resources)); | 44 RegisterStrings(values, resources, arraysize(resources)); |
| 45 RegisterTitle(values, "manageMediaGalleries", | 45 RegisterTitle(values, "manageMediaGalleries", |
| 46 IDS_MEDIA_GALLERY_MANAGE_TITLE); | 46 IDS_MEDIA_GALLERY_MANAGE_TITLE); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void MediaGalleriesHandler::InitializePage() { | 49 void MediaGalleriesHandler::InitializePage() { |
| 50 StorageMonitor::GetInstance()->EnsureInitialized( | 50 Profile* profile = Profile::FromWebUI(web_ui()); |
| 51 base::Bind(&MediaGalleriesHandler::InitializeOnStorageMonitorInit, | 51 MediaGalleriesPreferences* preferences = |
| 52 weak_ptr_factory_.GetWeakPtr())); | 52 g_browser_process->media_file_system_registry()->GetPreferences(profile); |
| 53 preferences->EnsureInitialized(base::Bind( |
| 54 &MediaGalleriesHandler::InitializeOnMediaGalleriesPreferencesInit, |
| 55 weak_ptr_factory_.GetWeakPtr())); |
| 53 } | 56 } |
| 54 | 57 |
| 55 void MediaGalleriesHandler::InitializeOnStorageMonitorInit() { | 58 void MediaGalleriesHandler::InitializeOnMediaGalleriesPreferencesInit() { |
| 56 Profile* profile = Profile::FromWebUI(web_ui()); | 59 Profile* profile = Profile::FromWebUI(web_ui()); |
| 57 if (!MediaGalleriesPreferences::APIHasBeenUsed(profile)) | 60 if (!MediaGalleriesPreferences::APIHasBeenUsed(profile)) |
| 58 return; | 61 return; |
| 59 | 62 |
| 60 if (pref_change_registrar_.IsEmpty()) { | 63 if (pref_change_registrar_.IsEmpty()) { |
| 61 pref_change_registrar_.Init(profile->GetPrefs()); | 64 pref_change_registrar_.Init(profile->GetPrefs()); |
| 62 pref_change_registrar_.Add( | 65 pref_change_registrar_.Add( |
| 63 prefs::kMediaGalleriesRememberedGalleries, | 66 prefs::kMediaGalleriesRememberedGalleries, |
| 64 base::Bind(&MediaGalleriesHandler::OnGalleriesChanged, | 67 base::Bind(&MediaGalleriesHandler::OnGalleriesChanged, |
| 65 base::Unretained(this))); | 68 base::Unretained(this))); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 83 "forgetGallery", | 86 "forgetGallery", |
| 84 base::Bind(&MediaGalleriesHandler::HandleForgetGallery, | 87 base::Bind(&MediaGalleriesHandler::HandleForgetGallery, |
| 85 base::Unretained(this))); | 88 base::Unretained(this))); |
| 86 } | 89 } |
| 87 | 90 |
| 88 void MediaGalleriesHandler::OnGalleriesChanged() { | 91 void MediaGalleriesHandler::OnGalleriesChanged() { |
| 89 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); | 92 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
| 90 Profile* profile = Profile::FromWebUI(web_ui()); | 93 Profile* profile = Profile::FromWebUI(web_ui()); |
| 91 MediaGalleriesPreferences* preferences = | 94 MediaGalleriesPreferences* preferences = |
| 92 g_browser_process->media_file_system_registry()->GetPreferences(profile); | 95 g_browser_process->media_file_system_registry()->GetPreferences(profile); |
| 96 DCHECK(preferences->IsInitialized()); |
| 93 | 97 |
| 94 ListValue list; | 98 ListValue list; |
| 95 const MediaGalleriesPrefInfoMap& galleries = preferences->known_galleries(); | 99 const MediaGalleriesPrefInfoMap& galleries = preferences->known_galleries(); |
| 96 for (MediaGalleriesPrefInfoMap::const_iterator iter = galleries.begin(); | 100 for (MediaGalleriesPrefInfoMap::const_iterator iter = galleries.begin(); |
| 97 iter != galleries.end(); ++iter) { | 101 iter != galleries.end(); ++iter) { |
| 98 const MediaGalleryPrefInfo& gallery = iter->second; | 102 const MediaGalleryPrefInfo& gallery = iter->second; |
| 99 if (gallery.type == MediaGalleryPrefInfo::kBlackListed) | 103 if (gallery.type == MediaGalleryPrefInfo::kBlackListed) |
| 100 continue; | 104 continue; |
| 101 | 105 |
| 102 DictionaryValue* dict = new DictionaryValue(); | 106 DictionaryValue* dict = new DictionaryValue(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 131 if (!args->GetString(0, &string_id) || | 135 if (!args->GetString(0, &string_id) || |
| 132 !base::StringToUint64(string_id, &id)) { | 136 !base::StringToUint64(string_id, &id)) { |
| 133 NOTREACHED(); | 137 NOTREACHED(); |
| 134 return; | 138 return; |
| 135 } | 139 } |
| 136 | 140 |
| 137 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); | 141 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
| 138 MediaGalleriesPreferences* preferences = | 142 MediaGalleriesPreferences* preferences = |
| 139 g_browser_process->media_file_system_registry()->GetPreferences( | 143 g_browser_process->media_file_system_registry()->GetPreferences( |
| 140 Profile::FromWebUI(web_ui())); | 144 Profile::FromWebUI(web_ui())); |
| 145 DCHECK(preferences->IsInitialized()); |
| 141 preferences->ForgetGalleryById(id); | 146 preferences->ForgetGalleryById(id); |
| 142 } | 147 } |
| 143 | 148 |
| 144 void MediaGalleriesHandler::FileSelected(const base::FilePath& path, | 149 void MediaGalleriesHandler::FileSelected(const base::FilePath& path, |
| 145 int index, | 150 int index, |
| 146 void* params) { | 151 void* params) { |
| 147 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); | 152 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
| 148 MediaGalleriesPreferences* preferences = | 153 MediaGalleriesPreferences* preferences = |
| 149 g_browser_process->media_file_system_registry()->GetPreferences( | 154 g_browser_process->media_file_system_registry()->GetPreferences( |
| 150 Profile::FromWebUI(web_ui())); | 155 Profile::FromWebUI(web_ui())); |
| 156 DCHECK(preferences->IsInitialized()); |
| 151 preferences->AddGalleryByPath(path); | 157 preferences->AddGalleryByPath(path); |
| 152 } | 158 } |
| 153 | 159 |
| 154 } // namespace options | 160 } // namespace options |
| OLD | NEW |