Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/supervised_user/permission_request_creator_sync.h" | 5 #include "chrome/browser/supervised_user/permission_request_creator_sync.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" | 9 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| 10 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service .h" | 10 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service .h" |
| 11 #include "net/base/escape.h" | |
| 11 | 12 |
| 12 using base::Time; | 13 using base::Time; |
| 13 | 14 |
| 14 const char kSupervisedUserAccessRequestKeyPrefix[] = | 15 const char kSupervisedUserAccessRequestKeyPrefix[] = |
| 15 "X-ManagedUser-AccessRequests"; | 16 "X-ManagedUser-AccessRequests"; |
| 16 const char kSupervisedUserAccessRequestTime[] = "timestamp"; | 17 const char kSupervisedUserAccessRequestTime[] = "timestamp"; |
| 17 const char kSupervisedUserName[] = "name"; | 18 const char kSupervisedUserName[] = "name"; |
| 18 | 19 |
| 19 // Key for the notification setting of the custodian. This is a shared setting | 20 // Key for the notification setting of the custodian. This is a shared setting |
| 20 // so we can include the setting in the access request data that is used to | 21 // so we can include the setting in the access request data that is used to |
| 21 // trigger notifications. | 22 // trigger notifications. |
| 22 const char kNotificationSetting[] = "custodian-notification-setting"; | 23 const char kNotificationSetting[] = "custodian-notification-setting"; |
| 23 | 24 |
| 24 PermissionRequestCreatorSync::PermissionRequestCreatorSync( | 25 PermissionRequestCreatorSync::PermissionRequestCreatorSync( |
| 25 SupervisedUserSettingsService* settings_service, | 26 SupervisedUserSettingsService* settings_service, |
| 26 SupervisedUserSharedSettingsService* shared_settings_service, | 27 SupervisedUserSharedSettingsService* shared_settings_service, |
| 27 const std::string& name, | 28 const std::string& name, |
| 28 const std::string& supervised_user_id) | 29 const std::string& supervised_user_id) |
| 29 : settings_service_(settings_service), | 30 : settings_service_(settings_service), |
| 30 shared_settings_service_(shared_settings_service), | 31 shared_settings_service_(shared_settings_service), |
| 31 name_(name), | 32 name_(name), |
| 32 supervised_user_id_(supervised_user_id) { | 33 supervised_user_id_(supervised_user_id) { |
| 33 } | 34 } |
| 34 | 35 |
| 35 PermissionRequestCreatorSync::~PermissionRequestCreatorSync() {} | 36 PermissionRequestCreatorSync::~PermissionRequestCreatorSync() {} |
| 36 | 37 |
| 37 void PermissionRequestCreatorSync::CreatePermissionRequest( | 38 void PermissionRequestCreatorSync::CreatePermissionRequest( |
| 38 const std::string& url_requested, | 39 const std::string& url_requested, |
|
Bernhard Bauer
2014/08/29 10:28:58
Can you make this a GURL now?
Marc Treib
2014/08/29 10:36:26
Yup. :)
| |
| 39 const base::Closure& callback) { | 40 const base::Closure& callback) { |
| 40 // Add the prefix. | 41 // Escape the URL and add the prefix. |
| 41 std::string key = SupervisedUserSettingsService::MakeSplitSettingKey( | 42 std::string key = SupervisedUserSettingsService::MakeSplitSettingKey( |
| 42 kSupervisedUserAccessRequestKeyPrefix, url_requested); | 43 kSupervisedUserAccessRequestKeyPrefix, |
| 44 net::EscapeQueryParamValue(url_requested, true)); | |
| 43 | 45 |
| 44 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 46 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 45 | 47 |
| 46 // TODO(sergiu): Use sane time here when it's ready. | 48 // TODO(sergiu): Use sane time here when it's ready. |
| 47 dict->SetDouble(kSupervisedUserAccessRequestTime, | 49 dict->SetDouble(kSupervisedUserAccessRequestTime, |
| 48 base::Time::Now().ToJsTime()); | 50 base::Time::Now().ToJsTime()); |
| 49 | 51 |
| 50 dict->SetString(kSupervisedUserName, name_); | 52 dict->SetString(kSupervisedUserName, name_); |
| 51 | 53 |
| 52 // Copy the notification setting of the custodian. | 54 // Copy the notification setting of the custodian. |
| 53 const base::Value* value = shared_settings_service_->GetValue( | 55 const base::Value* value = shared_settings_service_->GetValue( |
| 54 supervised_user_id_, kNotificationSetting); | 56 supervised_user_id_, kNotificationSetting); |
| 55 bool notifications_enabled = false; | 57 bool notifications_enabled = false; |
| 56 if (value) { | 58 if (value) { |
| 57 bool success = value->GetAsBoolean(¬ifications_enabled); | 59 bool success = value->GetAsBoolean(¬ifications_enabled); |
| 58 DCHECK(success); | 60 DCHECK(success); |
| 59 } | 61 } |
| 60 dict->SetBoolean(kNotificationSetting, notifications_enabled); | 62 dict->SetBoolean(kNotificationSetting, notifications_enabled); |
| 61 | 63 |
| 62 settings_service_->UploadItem(key, dict.PassAs<base::Value>()); | 64 settings_service_->UploadItem(key, dict.PassAs<base::Value>()); |
| 63 | 65 |
| 64 callback.Run(); | 66 callback.Run(); |
| 65 } | 67 } |
| OLD | NEW |