| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/options/personal_options_handler.h" | 5 #include "chrome/browser/dom_ui/options/personal_options_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #endif // defined(OS_CHROMEOS) | 38 #endif // defined(OS_CHROMEOS) |
| 39 #if defined(TOOLKIT_GTK) | 39 #if defined(TOOLKIT_GTK) |
| 40 #include "chrome/browser/gtk/gtk_theme_provider.h" | 40 #include "chrome/browser/gtk/gtk_theme_provider.h" |
| 41 #endif // defined(TOOLKIT_GTK) | 41 #endif // defined(TOOLKIT_GTK) |
| 42 | 42 |
| 43 PersonalOptionsHandler::PersonalOptionsHandler() { | 43 PersonalOptionsHandler::PersonalOptionsHandler() { |
| 44 } | 44 } |
| 45 | 45 |
| 46 PersonalOptionsHandler::~PersonalOptionsHandler() { | 46 PersonalOptionsHandler::~PersonalOptionsHandler() { |
| 47 ProfileSyncService* sync_service = | 47 ProfileSyncService* sync_service = |
| 48 dom_ui_->GetProfile()->GetProfileSyncService(); | 48 dom_ui_->GetOriginalProfile()->GetProfileSyncService(); |
| 49 if (sync_service) | 49 if (sync_service) |
| 50 sync_service->RemoveObserver(this); | 50 sync_service->RemoveObserver(this); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void PersonalOptionsHandler::GetLocalizedValues( | 53 void PersonalOptionsHandler::GetLocalizedValues( |
| 54 DictionaryValue* localized_strings) { | 54 DictionaryValue* localized_strings) { |
| 55 DCHECK(localized_strings); | 55 DCHECK(localized_strings); |
| 56 | 56 |
| 57 localized_strings->SetString("syncSection", | 57 localized_strings->SetString("syncSection", |
| 58 dom_options_util::StripColon( | 58 dom_options_util::StripColon( |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 const NotificationDetails& details) { | 146 const NotificationDetails& details) { |
| 147 if (type == NotificationType::BROWSER_THEME_CHANGED) | 147 if (type == NotificationType::BROWSER_THEME_CHANGED) |
| 148 ObserveThemeChanged(); | 148 ObserveThemeChanged(); |
| 149 else | 149 else |
| 150 OptionsPageUIHandler::Observe(type, source, details); | 150 OptionsPageUIHandler::Observe(type, source, details); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void PersonalOptionsHandler::OnStateChanged() { | 153 void PersonalOptionsHandler::OnStateChanged() { |
| 154 string16 status_label; | 154 string16 status_label; |
| 155 string16 link_label; | 155 string16 link_label; |
| 156 ProfileSyncService* service = dom_ui_->GetProfile()->GetProfileSyncService(); | 156 ProfileSyncService* service = |
| 157 dom_ui_->GetOriginalProfile()->GetProfileSyncService(); |
| 158 DCHECK(service); |
| 157 bool managed = service->IsManaged(); | 159 bool managed = service->IsManaged(); |
| 158 bool sync_setup_completed = service->HasSyncSetupCompleted(); | 160 bool sync_setup_completed = service->HasSyncSetupCompleted(); |
| 159 bool status_has_error = sync_ui_util::GetStatusLabels(service, | 161 bool status_has_error = sync_ui_util::GetStatusLabels(service, |
| 160 &status_label, &link_label) == sync_ui_util::SYNC_ERROR; | 162 &status_label, &link_label) == sync_ui_util::SYNC_ERROR; |
| 161 | 163 |
| 162 string16 start_stop_button_label; | 164 string16 start_stop_button_label; |
| 163 bool is_start_stop_button_visible = false; | 165 bool is_start_stop_button_visible = false; |
| 164 bool is_start_stop_button_enabled = false; | 166 bool is_start_stop_button_enabled = false; |
| 165 if (sync_setup_completed) { | 167 if (sync_setup_completed) { |
| 166 start_stop_button_label = | 168 start_stop_button_label = |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 new OptionsManagedBannerHandler(dom_ui_, | 251 new OptionsManagedBannerHandler(dom_ui_, |
| 250 ASCIIToUTF16("PersonalOptions"), | 252 ASCIIToUTF16("PersonalOptions"), |
| 251 OPTIONS_PAGE_CONTENT)); | 253 OPTIONS_PAGE_CONTENT)); |
| 252 | 254 |
| 253 // Listen for theme installation. | 255 // Listen for theme installation. |
| 254 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 256 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| 255 NotificationService::AllSources()); | 257 NotificationService::AllSources()); |
| 256 ObserveThemeChanged(); | 258 ObserveThemeChanged(); |
| 257 | 259 |
| 258 ProfileSyncService* sync_service = | 260 ProfileSyncService* sync_service = |
| 259 dom_ui_->GetProfile()->GetProfileSyncService(); | 261 dom_ui_->GetOriginalProfile()->GetProfileSyncService(); |
| 260 if (sync_service) { | 262 if (sync_service) { |
| 261 sync_service->AddObserver(this); | 263 sync_service->AddObserver(this); |
| 262 OnStateChanged(); | 264 OnStateChanged(); |
| 263 } else { | 265 } else { |
| 264 dom_ui_->CallJavascriptFunction(L"options.PersonalOptions.hideSyncSection"); | 266 dom_ui_->CallJavascriptFunction(L"options.PersonalOptions.hideSyncSection"); |
| 265 } | 267 } |
| 266 } | 268 } |
| 267 | 269 |
| 268 void PersonalOptionsHandler::ShowSyncLoginDialog(const ListValue* args) { | 270 void PersonalOptionsHandler::ShowSyncLoginDialog(const ListValue* args) { |
| 269 #if defined(OS_CHROMEOS) | 271 #if defined(OS_CHROMEOS) |
| 270 std::string email = chromeos::UserManager::Get()->logged_in_user().email(); | 272 std::string email = chromeos::UserManager::Get()->logged_in_user().email(); |
| 271 string16 message = l10n_util::GetStringFUTF16( | 273 string16 message = l10n_util::GetStringFUTF16( |
| 272 IDS_SYNC_LOGIN_INTRODUCTION, | 274 IDS_SYNC_LOGIN_INTRODUCTION, |
| 273 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 275 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| 274 dom_ui_->GetProfile()->GetBrowserSignin()->RequestSignin( | 276 dom_ui_->GetProfile()->GetBrowserSignin()->RequestSignin( |
| 275 dom_ui_->tab_contents(), UTF8ToUTF16(email), message, this); | 277 dom_ui_->tab_contents(), UTF8ToUTF16(email), message, this); |
| 276 #else | 278 #else |
| 277 ProfileSyncService* service = dom_ui_->GetProfile()->GetProfileSyncService(); | 279 ProfileSyncService* service = |
| 280 dom_ui_->GetOriginalProfile()->GetProfileSyncService(); |
| 281 DCHECK(service); |
| 278 service->ShowLoginDialog(NULL); | 282 service->ShowLoginDialog(NULL); |
| 279 ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_OPTIONS); | 283 ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_OPTIONS); |
| 280 #endif | 284 #endif |
| 281 } | 285 } |
| 282 | 286 |
| 283 void PersonalOptionsHandler::ThemesReset(const ListValue* args) { | 287 void PersonalOptionsHandler::ThemesReset(const ListValue* args) { |
| 284 UserMetricsRecordAction(UserMetricsAction("Options_ThemesReset")); | 288 UserMetricsRecordAction(UserMetricsAction("Options_ThemesReset")); |
| 285 dom_ui_->GetProfile()->ClearTheme(); | 289 dom_ui_->GetProfile()->ClearTheme(); |
| 286 } | 290 } |
| 287 | 291 |
| 288 #if defined(TOOLKIT_GTK) | 292 #if defined(TOOLKIT_GTK) |
| 289 void PersonalOptionsHandler::ThemesSetGTK(const ListValue* args) { | 293 void PersonalOptionsHandler::ThemesSetGTK(const ListValue* args) { |
| 290 UserMetricsRecordAction(UserMetricsAction("Options_GtkThemeSet")); | 294 UserMetricsRecordAction(UserMetricsAction("Options_GtkThemeSet")); |
| 291 dom_ui_->GetProfile()->SetNativeTheme(); | 295 dom_ui_->GetProfile()->SetNativeTheme(); |
| 292 } | 296 } |
| 293 #endif | 297 #endif |
| 294 | 298 |
| 295 void PersonalOptionsHandler::OnLoginSuccess() { | 299 void PersonalOptionsHandler::OnLoginSuccess() { |
| 296 OnStateChanged(); | 300 OnStateChanged(); |
| 297 } | 301 } |
| 298 | 302 |
| 299 void PersonalOptionsHandler::OnLoginFailure( | 303 void PersonalOptionsHandler::OnLoginFailure( |
| 300 const GoogleServiceAuthError& error) { | 304 const GoogleServiceAuthError& error) { |
| 301 OnStateChanged(); | 305 OnStateChanged(); |
| 302 } | 306 } |
| OLD | NEW |