Index: chrome/browser/chromeos/policy/consumer_management_service.cc |
diff --git a/chrome/browser/chromeos/policy/consumer_management_service.cc b/chrome/browser/chromeos/policy/consumer_management_service.cc |
index 736ad0014bdc884f6794f9f9ebe660d85e9fef25..247bdaf58c735d2034cb02fab1818c628ed4e6fa 100644 |
--- a/chrome/browser/chromeos/policy/consumer_management_service.cc |
+++ b/chrome/browser/chromeos/policy/consumer_management_service.cc |
@@ -11,6 +11,7 @@ |
#include "base/message_loop/message_loop.h" |
#include "base/prefs/pref_registry_simple.h" |
#include "base/prefs/pref_service.h" |
+#include "base/strings/utf_string_conversions.h" |
#include "base/time/time.h" |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/browser_process_platform_part.h" |
@@ -19,10 +20,14 @@ |
#include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" |
#include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" |
#include "chrome/browser/chromeos/profiles/profile_helper.h" |
+#include "chrome/browser/notifications/notification.h" |
+#include "chrome/browser/notifications/notification_ui_manager.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
#include "chrome/browser/signin/signin_manager_factory.h" |
+#include "chrome/browser/ui/browser_navigator.h" |
#include "chrome/common/pref_names.h" |
+#include "chrome/common/url_constants.h" |
#include "chromeos/dbus/cryptohome/rpc.pb.h" |
#include "chromeos/dbus/cryptohome_client.h" |
#include "components/policy/core/common/cloud/cloud_policy_constants.h" |
@@ -32,14 +37,31 @@ |
#include "content/public/browser/notification_details.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/notification_source.h" |
+#include "content/public/browser/web_contents.h" |
bartfab (slow)
2014/08/20 13:55:49
Nit: Not used.
davidyu
2014/08/21 04:08:25
Done.
|
+#include "content/public/common/page_transition_types.h" |
#include "google_apis/gaia/gaia_constants.h" |
#include "google_apis/gaia/google_service_auth_error.h" |
+#include "grit/generated_resources.h" |
+#include "grit/theme_resources.h" |
#include "policy/proto/device_management_backend.pb.h" |
+#include "ui/base/l10n/l10n_util.h" |
+#include "ui/base/resource/resource_bundle.h" |
+#include "ui/base/window_open_disposition.h" |
+#include "ui/message_center/notifier_settings.h" |
+#include "url/gurl.h" |
namespace { |
+// Boot atttributes ID. |
const char* kAttributeOwnerId = "consumer_management.owner_id"; |
oshima
2014/08/20 13:24:00
const char[]
davidyu
2014/08/21 04:08:24
Done.
|
+// Desktop notification constants. |
+const char* kEnrollmentNotificationId = "consumer_management.enroll"; |
+const char* kEnrollmentNotificationUrl = "chrome://consumer-management/enroll"; |
+ |
+// URL |
bartfab (slow)
2014/08/20 13:55:50
This is not a URL. This is a path to something. Pl
davidyu
2014/08/21 04:08:24
Done.
|
+const char* kConsumerManagementOverlay = "/consumer-management-overlay"; |
oshima
2014/08/20 13:24:01
ditto
davidyu
2014/08/21 04:08:24
Done.
|
+ |
} // namespace |
namespace policy { |
@@ -219,7 +241,7 @@ void ConsumerManagementService::OnOwnerSignin(Profile* profile) { |
case ENROLLMENT_BOOT_LOCKBOX_FAILED: |
case ENROLLMENT_DM_SERVER_FAILED: |
case ENROLLMENT_GET_TOKEN_FAILED: |
- ShowDesktopNotificationAndResetState(state); |
+ ShowDesktopNotificationAndResetState(state, profile); |
return; |
case ENROLLMENT_REQUESTED: |
@@ -233,10 +255,12 @@ void ConsumerManagementService::ContinueEnrollmentProcess(Profile* profile) { |
// First, we need to ensure that the refresh token is available. |
SigninManagerBase* signin_manager = |
SigninManagerFactory::GetForProfile(profile); |
- enrolling_account_id_ = signin_manager->GetAuthenticatedAccountId(); |
+ enrolling_account_id_ = signin_manager->GetAuthenticatedAccountId(); |
+ enrolling_profile_ = profile; |
enrolling_token_service_ = |
ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
+ |
if (enrolling_token_service_->RefreshTokenIsAvailable( |
enrolling_account_id_)) { |
OnOwnerRefreshTokenAvailable(); |
@@ -297,16 +321,118 @@ void ConsumerManagementService::OnEnrollmentCompleted(EnrollmentStatus status) { |
} |
void ConsumerManagementService::EndEnrollment(ConsumerEnrollmentState state) { |
+ Profile* profile = enrolling_profile_; |
+ |
+ enrolling_account_id_.clear(); |
+ enrolling_profile_ = NULL; |
+ enrolling_token_service_ = NULL; |
+ |
SetEnrollmentState(state); |
if (user_manager::UserManager::Get()->IsCurrentUserOwner()) |
- ShowDesktopNotificationAndResetState(state); |
+ ShowDesktopNotificationAndResetState(state, profile); |
} |
void ConsumerManagementService::ShowDesktopNotificationAndResetState( |
- ConsumerEnrollmentState state) { |
- // TODO(davidyu): Show a desktop notification to the current user, who should |
- // be the owner. |
+ ConsumerEnrollmentState state, Profile* profile) { |
+ base::string16 title, body, button_label; |
bartfab (slow)
2014/08/20 13:55:49
Nit: Declare one variable per line.
davidyu
2014/08/21 04:08:24
Done.
|
+ base::Closure button_click_callback; |
+ |
+ if (state == ENROLLMENT_SUCCESS) { |
+ title =l10n_util::GetStringUTF16( |
bartfab (slow)
2014/08/20 13:55:50
Nit: s/=/= /
davidyu
2014/08/21 04:08:25
Done.
|
+ IDS_CONSUMER_MANAGEMENT_ENROLLMENT_NOTIFICATION_TITLE); |
+ body = l10n_util::GetStringUTF16( |
+ IDS_CONSUMER_MANAGEMENT_ENROLLMENT_NOTIFICATION_BODY); |
+ button_label = l10n_util::GetStringUTF16( |
+ IDS_CONSUMER_MANAGEMENT_NOTIFICATION_MODIFY_SETTINGS_BUTTON); |
+ button_click_callback = base::Bind( |
+ &ConsumerManagementService::OpenSettingsPage, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ profile); |
+ } else { |
+ title =l10n_util::GetStringUTF16( |
bartfab (slow)
2014/08/20 13:55:50
Nit: s/=/= /
davidyu
2014/08/21 04:08:24
Done.
|
+ IDS_CONSUMER_MANAGEMENT_ENROLLMENT_FAILURE_NOTIFICATION_TITLE); |
+ body = l10n_util::GetStringUTF16( |
+ IDS_CONSUMER_MANAGEMENT_ENROLLMENT_FAILURE_NOTIFICATION_BODY); |
+ button_label = l10n_util::GetStringUTF16( |
+ IDS_CONSUMER_MANAGEMENT_NOTIFICATION_TRY_AGAIN_BUTTON); |
+ button_click_callback = base::Bind( |
+ &ConsumerManagementService::TryEnrollmentAgain, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ profile); |
+ } |
+ |
+ ShowDesktopNotification( |
+ profile, |
+ kEnrollmentNotificationId, |
+ kEnrollmentNotificationUrl, |
+ title, |
+ body, |
+ button_label, |
+ button_click_callback); |
+ |
SetEnrollmentState(ENROLLMENT_NONE); |
} |
+void ConsumerManagementService::OpenSettingsPage(Profile* profile) const { |
+ GURL url(chrome::kChromeUISettingsURL); |
bartfab (slow)
2014/08/20 13:55:49
Nit: const.
davidyu
2014/08/21 04:08:25
Done.
|
+ chrome::NavigateParams params(profile, url, content::PAGE_TRANSITION_LINK); |
+ params.disposition = NEW_FOREGROUND_TAB; |
+ chrome::Navigate(¶ms); |
+ return; |
oshima
2014/08/20 13:24:01
remove this
bartfab (slow)
2014/08/20 13:55:50
Nit: No need for a return here.
davidyu
2014/08/21 04:08:24
Done.
|
+} |
+ |
+void ConsumerManagementService::TryEnrollmentAgain(Profile* profile) const { |
+ std::string url_string(chrome::kChromeUISettingsURL); |
+ url_string.append(kConsumerManagementOverlay); |
bartfab (slow)
2014/08/20 13:55:51
Nit: Instead of concatenating strings and then tur
davidyu
2014/08/21 04:08:25
Done.
|
+ |
+ GURL url(url_string); |
bartfab (slow)
2014/08/20 13:55:51
Nit: const.
davidyu
2014/08/21 04:08:24
Removed.
|
+ chrome::NavigateParams params(profile, url, content::PAGE_TRANSITION_LINK); |
+ params.disposition = NEW_FOREGROUND_TAB; |
+ chrome::Navigate(¶ms); |
+} |
+ |
+void ConsumerManagementService::ShowDesktopNotification( |
bartfab (slow)
2014/08/20 13:55:50
Nit: You could fold this into ShowDesktopNotificat
davidyu
2014/08/21 04:08:24
Done.
|
+ Profile* profile, |
+ const std::string& id, |
bartfab (slow)
2014/08/20 13:55:49
Nit: This will always be kEnrollmentNotificationId
davidyu
2014/08/21 04:08:24
Done.
|
+ const std::string& origin_url, |
bartfab (slow)
2014/08/20 13:55:49
Nit: This will always be kEnrollmentNotificationUr
davidyu
2014/08/21 04:08:24
Done.
|
+ const base::string16& title, |
+ const base::string16& body, |
+ const base::string16& button_label, |
+ const base::Closure& button_click_callback) const { |
+ message_center::RichNotificationData optional_field; |
bartfab (slow)
2014/08/20 13:55:49
Nit: #include "ui/message_center/notification.h"
davidyu
2014/08/21 04:08:24
Done.
|
+ optional_field.buttons.push_back(message_center::ButtonInfo(button_label)); |
+ |
+ scoped_ptr<Notification> notification( |
bartfab (slow)
2014/08/20 13:55:50
Why do you use a scoped_ptr instead of a stack obj
davidyu
2014/08/21 04:08:25
Converted it back to a simple local variable.
|
+ new Notification( |
+ message_center::NOTIFICATION_TYPE_SIMPLE, |
bartfab (slow)
2014/08/20 13:55:51
Nit: #include "ui/message_center/notification_type
davidyu
2014/08/21 04:08:24
Done.
|
+ GURL(origin_url), |
+ title, |
+ body, |
+ ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
+ IDR_CONSUMER_MANAGEMENT_NOTIFICATION_ICON), |
+ blink::WebTextDirectionDefault, |
bartfab (slow)
2014/08/20 13:55:49
Nit: #include "third_party/WebKit/public/web/WebTe
davidyu
2014/08/21 04:08:24
Done.
|
+ message_center::NotifierId( |
+ message_center::NotifierId::SYSTEM_COMPONENT, id), |
+ base::string16(), // display_source |
+ base::UTF8ToUTF16(id), |
+ optional_field, |
+ new DesktopNotificationDelegate(id, button_click_callback))); |
+ notification->SetSystemPriority(); |
+ |
+ g_browser_process->notification_ui_manager()->Add(*notification, profile); |
+} |
+ |
+ConsumerManagementService::DesktopNotificationDelegate:: |
bartfab (slow)
2014/08/20 13:55:50
Nit: Declaration and definition order should match
davidyu
2014/08/21 04:08:24
Done.
|
+DesktopNotificationDelegate( |
bartfab (slow)
2014/08/20 13:55:49
Nit: Indent four spaces.
davidyu
2014/08/21 04:08:24
Done.
|
+ const std::string& id, |
+ const base::Closure& button_click_callback) |
+ : id_(id), |
+ button_click_callback_(button_click_callback) { |
+} |
+ |
+void ConsumerManagementService::DesktopNotificationDelegate::ButtonClick( |
+ int button_index) { |
+ button_click_callback_.Run(); |
+} |
+ |
} // namespace policy |