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/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "chrome/browser/media_gallery/media_file_system_registry.h" |
9 #include "chrome/browser/media_gallery/media_galleries_preferences.h" | 10 #include "chrome/browser/media_gallery/media_galleries_preferences.h" |
10 #include "chrome/browser/media_gallery/media_galleries_preferences_factory.h" | |
11 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/chrome_select_file_policy.h" | 13 #include "chrome/browser/ui/chrome_select_file_policy.h" |
14 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_contents_view.h" | 18 #include "content/public/browser/web_contents_view.h" |
19 #include "content/public/browser/web_ui.h" | 19 #include "content/public/browser/web_ui.h" |
20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 base::Unretained(this))); | 65 base::Unretained(this))); |
66 web_ui()->RegisterMessageCallback( | 66 web_ui()->RegisterMessageCallback( |
67 "forgetGallery", | 67 "forgetGallery", |
68 base::Bind(&MediaGalleriesHandler::HandleForgetGallery, | 68 base::Bind(&MediaGalleriesHandler::HandleForgetGallery, |
69 base::Unretained(this))); | 69 base::Unretained(this))); |
70 } | 70 } |
71 | 71 |
72 void MediaGalleriesHandler::OnGalleriesChanged() { | 72 void MediaGalleriesHandler::OnGalleriesChanged() { |
73 Profile* profile = Profile::FromWebUI(web_ui()); | 73 Profile* profile = Profile::FromWebUI(web_ui()); |
74 chrome::MediaGalleriesPreferences* preferences = | 74 chrome::MediaGalleriesPreferences* preferences = |
75 MediaGalleriesPreferencesFactory::GetForProfile(profile); | 75 chrome::MediaFileSystemRegistry::GetInstance()->GetPreferences(profile); |
76 | 76 |
77 ListValue list; | 77 ListValue list; |
78 const MediaGalleriesPrefInfoMap& galleries = preferences->known_galleries(); | 78 const MediaGalleriesPrefInfoMap& galleries = preferences->known_galleries(); |
79 for (MediaGalleriesPrefInfoMap::const_iterator iter = galleries.begin(); | 79 for (MediaGalleriesPrefInfoMap::const_iterator iter = galleries.begin(); |
80 iter != galleries.end(); ++iter) { | 80 iter != galleries.end(); ++iter) { |
81 const MediaGalleryPrefInfo& gallery = iter->second; | 81 const MediaGalleryPrefInfo& gallery = iter->second; |
82 if (gallery.type == MediaGalleryPrefInfo::kBlackListed) | 82 if (gallery.type == MediaGalleryPrefInfo::kBlackListed) |
83 continue; | 83 continue; |
84 | 84 |
85 DictionaryValue* dict = new DictionaryValue(); | 85 DictionaryValue* dict = new DictionaryValue(); |
(...skipping 24 matching lines...) Expand all Loading... |
110 void MediaGalleriesHandler::HandleForgetGallery(const base::ListValue* args) { | 110 void MediaGalleriesHandler::HandleForgetGallery(const base::ListValue* args) { |
111 std::string string_id; | 111 std::string string_id; |
112 uint64 id = 0; | 112 uint64 id = 0; |
113 if (!args->GetString(0, &string_id) || | 113 if (!args->GetString(0, &string_id) || |
114 !base::StringToUint64(string_id, &id)) { | 114 !base::StringToUint64(string_id, &id)) { |
115 NOTREACHED(); | 115 NOTREACHED(); |
116 return; | 116 return; |
117 } | 117 } |
118 | 118 |
119 chrome::MediaGalleriesPreferences* prefs = | 119 chrome::MediaGalleriesPreferences* prefs = |
120 MediaGalleriesPreferencesFactory::GetForProfile( | 120 chrome::MediaFileSystemRegistry::GetInstance()->GetPreferences( |
121 Profile::FromWebUI(web_ui())); | 121 Profile::FromWebUI(web_ui())); |
122 prefs->ForgetGalleryById(id); | 122 prefs->ForgetGalleryById(id); |
123 } | 123 } |
124 | 124 |
125 void MediaGalleriesHandler::FileSelected( | 125 void MediaGalleriesHandler::FileSelected( |
126 const FilePath& path, int index, void* params) { | 126 const FilePath& path, int index, void* params) { |
127 chrome::MediaGalleriesPreferences* prefs = | 127 chrome::MediaGalleriesPreferences* prefs = |
128 MediaGalleriesPreferencesFactory::GetForProfile( | 128 chrome::MediaFileSystemRegistry::GetInstance()->GetPreferences( |
129 Profile::FromWebUI(web_ui())); | 129 Profile::FromWebUI(web_ui())); |
130 prefs->AddGalleryByPath(path); | 130 prefs->AddGalleryByPath(path); |
131 } | 131 } |
132 | 132 |
133 void MediaGalleriesHandler::Observe( | 133 void MediaGalleriesHandler::Observe( |
134 int type, | 134 int type, |
135 const content::NotificationSource& source, | 135 const content::NotificationSource& source, |
136 const content::NotificationDetails& details) { | 136 const content::NotificationDetails& details) { |
137 if (type == chrome::NOTIFICATION_PREF_CHANGED && | 137 if (type == chrome::NOTIFICATION_PREF_CHANGED && |
138 *content::Details<std::string>(details).ptr() == | 138 *content::Details<std::string>(details).ptr() == |
139 prefs::kMediaGalleriesRememberedGalleries) { | 139 prefs::kMediaGalleriesRememberedGalleries) { |
140 OnGalleriesChanged(); | 140 OnGalleriesChanged(); |
141 } else { | 141 } else { |
142 NOTREACHED(); | 142 NOTREACHED(); |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 } // namespace options | 146 } // namespace options |
OLD | NEW |