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.
5 #include "chrome/browser/supervised_user/permission_request_creator_sync.h"
7 #include "base/callback.h"
8 #include "base/values.h"
9 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
10 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service.h"
14 const char kSupervisedUserAccessRequestKeyPrefix[] =
15 "X-ManagedUser-AccessRequests";
16 const char kSupervisedUserAccessRequestTime[] = "timestamp";
17 const char kSupervisedUserName[] = "name";
19 // 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 // trigger notifications.
22 const char kNotificationSetting[] = "custodian-notification-setting";
24 PermissionRequestCreatorSync::PermissionRequestCreatorSync(
25 SupervisedUserSettingsService* settings_service,
26 SupervisedUserSharedSettingsService* shared_settings_service,
27 const std::string& name,
28 const std::string& supervised_user_id)
29 : settings_service_(settings_service),
30 shared_settings_service_(shared_settings_service),
32 supervised_user_id_(supervised_user_id) {
35 PermissionRequestCreatorSync::~PermissionRequestCreatorSync() {}
37 void PermissionRequestCreatorSync::CreatePermissionRequest(
38 const std::string& url_requested,
39 const base::Closure& callback) {
41 std::string key = SupervisedUserSettingsService::MakeSplitSettingKey(
42 kSupervisedUserAccessRequestKeyPrefix, url_requested);
44 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
46 // TODO(sergiu): Use sane time here when it's ready.
47 dict->SetDouble(kSupervisedUserAccessRequestTime,
48 base::Time::Now().ToJsTime());
50 dict->SetString(kSupervisedUserName, name_);
52 // Copy the notification setting of the custodian.
53 const base::Value* value = shared_settings_service_->GetValue(
54 supervised_user_id_, kNotificationSetting);
55 bool notifications_enabled = false;
57 bool success = value->GetAsBoolean(¬ifications_enabled);
60 dict->SetBoolean(kNotificationSetting, notifications_enabled);
62 settings_service_->UploadItem(key, dict.PassAs<base::Value>());