Move Webstore URL concepts to //extensions and out
[chromium-blink-merge.git] / chrome / browser / supervised_user / permission_request_creator_sync.cc
blob328bf21c5d083ccd01beecca2fd4ac6bf4a587e5
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"
11 #include "net/base/escape.h"
12 #include "url/gurl.h"
14 using base::Time;
16 const char kSupervisedUserAccessRequestKeyPrefix[] =
17 "X-ManagedUser-AccessRequests";
18 const char kSupervisedUserAccessRequestTime[] = "timestamp";
19 const char kSupervisedUserName[] = "name";
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
23 // trigger notifications.
24 const char kNotificationSetting[] = "custodian-notification-setting";
26 PermissionRequestCreatorSync::PermissionRequestCreatorSync(
27 SupervisedUserSettingsService* settings_service,
28 SupervisedUserSharedSettingsService* shared_settings_service,
29 const std::string& name,
30 const std::string& supervised_user_id)
31 : settings_service_(settings_service),
32 shared_settings_service_(shared_settings_service),
33 name_(name),
34 supervised_user_id_(supervised_user_id) {
37 PermissionRequestCreatorSync::~PermissionRequestCreatorSync() {}
39 void PermissionRequestCreatorSync::CreatePermissionRequest(
40 const GURL& url_requested,
41 const base::Closure& callback) {
42 // Escape the URL and add the prefix.
43 std::string key = SupervisedUserSettingsService::MakeSplitSettingKey(
44 kSupervisedUserAccessRequestKeyPrefix,
45 net::EscapeQueryParamValue(url_requested.spec(), true));
47 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
49 // TODO(sergiu): Use sane time here when it's ready.
50 dict->SetDouble(kSupervisedUserAccessRequestTime,
51 base::Time::Now().ToJsTime());
53 dict->SetString(kSupervisedUserName, name_);
55 // Copy the notification setting of the custodian.
56 const base::Value* value = shared_settings_service_->GetValue(
57 supervised_user_id_, kNotificationSetting);
58 bool notifications_enabled = false;
59 if (value) {
60 bool success = value->GetAsBoolean(&notifications_enabled);
61 DCHECK(success);
63 dict->SetBoolean(kNotificationSetting, notifications_enabled);
65 settings_service_->UploadItem(key, dict.PassAs<base::Value>());
67 callback.Run();