Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(336)

Side by Side Diff: chrome/browser/policy/device_management_service.h

Issue 12189011: Split up chrome/browser/policy subdirectory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_H_
6 #define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_H_
7
8 #include <deque>
9 #include <map>
10 #include <string>
11 #include <vector>
12
13 #include "base/basictypes.h"
14 #include "base/callback.h"
15 #include "base/compiler_specific.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/memory/weak_ptr.h"
18 #include "chrome/browser/policy/cloud_policy_constants.h"
19 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
20 #include "net/url_request/url_fetcher_delegate.h"
21
22 namespace net {
23 class URLRequestContextGetter;
24 }
25
26 namespace policy {
27
28 class DeviceManagementRequestJobImpl;
29 class DeviceManagementService;
30
31 // DeviceManagementRequestJob describes a request to send to the device
32 // management service. Jobs are created by DeviceManagementService. They can be
33 // canceled by deleting the object.
34 class DeviceManagementRequestJob {
35 public:
36 // Describes the job type.
37 enum JobType {
38 TYPE_AUTO_ENROLLMENT,
39 TYPE_REGISTRATION,
40 TYPE_POLICY_FETCH,
41 TYPE_UNREGISTRATION,
42 };
43
44 typedef base::Callback<
45 void(DeviceManagementStatus,
46 const enterprise_management::DeviceManagementResponse&)> Callback;
47
48 virtual ~DeviceManagementRequestJob();
49
50 // Functions for configuring the job. These should only be called before
51 // Start()ing the job, but never afterwards.
52 void SetGaiaToken(const std::string& gaia_token);
53 void SetOAuthToken(const std::string& oauth_token);
54 void SetUserAffiliation(UserAffiliation user_affiliation);
55 void SetDMToken(const std::string& dm_token);
56 void SetClientID(const std::string& client_id);
57 enterprise_management::DeviceManagementRequest* GetRequest();
58
59 // Starts the job. |callback| will be invoked on completion.
60 void Start(const DeviceManagementRequestJob::Callback& callback);
61
62 protected:
63 typedef std::vector<std::pair<std::string, std::string> > ParameterMap;
64
65 explicit DeviceManagementRequestJob(JobType type);
66
67 // Appends a parameter to |query_params|.
68 void AddParameter(const std::string& name, const std::string& value);
69
70 // Fires the job, to be filled in by implementations.
71 virtual void Run() = 0;
72
73 ParameterMap query_params_;
74 std::string gaia_token_;
75 std::string dm_token_;
76 enterprise_management::DeviceManagementRequest request_;
77
78 Callback callback_;
79
80 private:
81 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRequestJob);
82 };
83
84 // The device management service is responsible for everything related to
85 // communication with the device management server. It creates the backends
86 // objects that the device management policy provider and friends use to issue
87 // requests.
88 class DeviceManagementService : public net::URLFetcherDelegate {
89 public:
90 explicit DeviceManagementService(const std::string& server_url);
91 virtual ~DeviceManagementService();
92
93 // Creates a new device management request job. Ownership is transferred to
94 // the caller.
95 virtual DeviceManagementRequestJob* CreateJob(
96 DeviceManagementRequestJob::JobType type);
97
98 // Schedules a task to run |Initialize| after |delay_milliseconds| had passed.
99 void ScheduleInitialization(int64 delay_milliseconds);
100
101 // Makes the service stop all requests and drop the reference to the request
102 // context.
103 void Shutdown();
104
105 private:
106 typedef std::map<const net::URLFetcher*,
107 DeviceManagementRequestJobImpl*> JobFetcherMap;
108 typedef std::deque<DeviceManagementRequestJobImpl*> JobQueue;
109
110 friend class DeviceManagementRequestJobImpl;
111
112 // net::URLFetcherDelegate override.
113 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
114
115 // Does the actual initialization using the request context specified for
116 // |PrepareInitialization|. This will also fire any pending network requests.
117 void Initialize();
118
119 // Starts a job.
120 void StartJob(DeviceManagementRequestJobImpl* job, bool bypass_proxy);
121
122 // Adds a job. Caller must make sure the job pointer stays valid until the job
123 // completes or gets canceled via RemoveJob().
124 void AddJob(DeviceManagementRequestJobImpl* job);
125
126 // Removes a job. The job will be removed and won't receive a completion
127 // callback.
128 void RemoveJob(DeviceManagementRequestJobImpl* job);
129
130 // Server at which to contact the service.
131 const std::string server_url_;
132
133 // The request context we use.
134 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
135
136 // The jobs we currently have in flight.
137 JobFetcherMap pending_jobs_;
138
139 // Jobs that are registered, but not started yet.
140 JobQueue queued_jobs_;
141
142 // If this service is initialized, incoming requests get fired instantly.
143 // If it is not initialized, incoming requests are queued.
144 bool initialized_;
145
146 // Used to create tasks to run |Initialize| delayed on the UI thread.
147 base::WeakPtrFactory<DeviceManagementService> weak_ptr_factory_;
148
149 DISALLOW_COPY_AND_ASSIGN(DeviceManagementService);
150 };
151
152 } // namespace policy
153
154 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698