OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/managed_mode/permission_request_creator_sync.h" |
| 6 |
| 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" |
| 9 #include "base/values.h" |
| 10 #include "chrome/browser/managed_mode/managed_user_settings_service.h" |
| 11 #include "chrome/browser/managed_mode/managed_user_shared_settings_service.h" |
| 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "google_apis/gaia/google_service_auth_error.h" |
| 14 |
| 15 using base::Time; |
| 16 |
| 17 const char kManagedUserAccessRequestKeyPrefix[] = |
| 18 "X-ManagedUser-AccessRequests"; |
| 19 const char kManagedUserAccessRequestTime[] = "timestamp"; |
| 20 const char kManagedUserName[] = "name"; |
| 21 |
| 22 // Key for the notification setting of the custodian. This is a shared setting |
| 23 // so we can include the setting in the access request data that is used to |
| 24 // trigger notifications. |
| 25 const char kNotificationSetting[] = "custodian-notification-setting"; |
| 26 |
| 27 PermissionRequestCreatorSync::PermissionRequestCreatorSync( |
| 28 ManagedUserSettingsService* settings_service, |
| 29 ManagedUserSharedSettingsService* shared_settings_service, |
| 30 const std::string& name, |
| 31 const std::string& managed_user_id) |
| 32 : settings_service_(settings_service), |
| 33 shared_settings_service_(shared_settings_service), |
| 34 name_(name), |
| 35 managed_user_id_(managed_user_id) { |
| 36 } |
| 37 |
| 38 PermissionRequestCreatorSync::~PermissionRequestCreatorSync() {} |
| 39 |
| 40 // static |
| 41 scoped_ptr<PermissionRequestCreator> |
| 42 PermissionRequestCreatorSync::Create( |
| 43 ManagedUserSettingsService* settings_service, |
| 44 ManagedUserSharedSettingsService* shared_settings_service, |
| 45 const std::string& name, |
| 46 const std::string& managed_user_id) { |
| 47 scoped_ptr<PermissionRequestCreator> creator(new PermissionRequestCreatorSync( |
| 48 settings_service, shared_settings_service, name, managed_user_id)); |
| 49 return creator.Pass(); |
| 50 } |
| 51 |
| 52 void PermissionRequestCreatorSync::CreatePermissionRequest( |
| 53 const std::string& url_requested, |
| 54 const PermissionRequestCallback& callback) { |
| 55 // Add the prefix. |
| 56 std::string key = ManagedUserSettingsService::MakeSplitSettingKey( |
| 57 kManagedUserAccessRequestKeyPrefix, url_requested); |
| 58 |
| 59 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 60 |
| 61 // TODO(sergiu): Use sane time here when it's ready. |
| 62 dict->SetDouble(kManagedUserAccessRequestTime, base::Time::Now().ToJsTime()); |
| 63 |
| 64 dict->SetString(kManagedUserName, name_); |
| 65 |
| 66 // Copy the notification setting of the custodian. |
| 67 const base::Value* value = shared_settings_service_->GetValue( |
| 68 managed_user_id_, kNotificationSetting); |
| 69 bool notifications_enabled = false; |
| 70 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 71 switches::kEnableAccessRequestNotifications)) { |
| 72 notifications_enabled = true; |
| 73 } else if (value) { |
| 74 bool success = value->GetAsBoolean(¬ifications_enabled); |
| 75 DCHECK(success); |
| 76 } |
| 77 dict->SetBoolean(kNotificationSetting, notifications_enabled); |
| 78 |
| 79 settings_service_->UploadItem(key, dict.PassAs<base::Value>()); |
| 80 |
| 81 callback.Run(GoogleServiceAuthError(GoogleServiceAuthError::NONE)); |
| 82 } |
OLD | NEW |