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