blob: 88ef5a353e1b5c4fbc3fdd8cff6efa90db6c4805 [file] [log] [blame]
[email protected]18a4d63c82012-05-25 23:37:031// 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#include "chrome/browser/pepper_flash_settings_manager.h"
6
[email protected]1a559442012-05-27 07:18:467#include <map>
8#include <utility>
[email protected]18a4d63c82012-05-25 23:37:039#include <vector>
10
[email protected]1a559442012-05-27 07:18:4611#include "base/bind.h"
12#include "base/compiler_specific.h"
13#include "base/sequenced_task_runner_helpers.h"
14#include "base/utf_string_conversions.h"
[email protected]0f5e57f52012-09-20 20:53:1815#include "chrome/browser/plugins/plugin_prefs.h"
[email protected]18a4d63c82012-05-25 23:37:0316#include "chrome/browser/prefs/pref_service.h"
[email protected]1a559442012-05-27 07:18:4617#include "chrome/browser/profiles/profile.h"
[email protected]18a4d63c82012-05-25 23:37:0318#include "chrome/common/pref_names.h"
[email protected]1a559442012-05-27 07:18:4619#include "content/public/browser/browser_context.h"
20#include "content/public/browser/browser_thread.h"
21#include "content/public/browser/pepper_flash_settings_helper.h"
[email protected]18a4d63c82012-05-25 23:37:0322#include "content/public/browser/plugin_service.h"
[email protected]1a559442012-05-27 07:18:4623#include "content/public/common/content_constants.h"
[email protected]18a4d63c82012-05-25 23:37:0324#include "googleurl/src/gurl.h"
[email protected]1a559442012-05-27 07:18:4625#include "ipc/ipc_channel.h"
26#include "ppapi/proxy/ppapi_messages.h"
[email protected]18a4d63c82012-05-25 23:37:0327#include "webkit/plugins/plugin_constants.h"
28#include "webkit/plugins/webplugininfo.h"
29
[email protected]1a559442012-05-27 07:18:4630using content::BrowserThread;
31
32class PepperFlashSettingsManager::Core
[email protected]b44f8ad2012-06-15 20:52:5833 : public IPC::Listener,
[email protected]1a559442012-05-27 07:18:4634 public base::RefCountedThreadSafe<Core, BrowserThread::DeleteOnIOThread> {
35 public:
[email protected]7c826912012-10-01 22:05:2736 Core(base::WeakPtr<PepperFlashSettingsManager> manager,
[email protected]1a559442012-05-27 07:18:4637 content::BrowserContext* browser_context);
38
[email protected]6464cc12012-07-12 09:25:5339 void Initialize();
[email protected]7c826912012-10-01 22:05:2740
41 // Notifies the core that it has been detached. Afterwards, no method should
42 // be called any more.
[email protected]1a559442012-05-27 07:18:4643 void Detach();
44
45 void DeauthorizeContentLicenses(uint32 request_id);
[email protected]ee4dd682012-06-12 15:49:3346 void GetPermissionSettings(
47 uint32 request_id,
48 PP_Flash_BrowserOperations_SettingType setting_type);
49 void SetDefaultPermission(
50 uint32 request_id,
51 PP_Flash_BrowserOperations_SettingType setting_type,
52 PP_Flash_BrowserOperations_Permission permission,
53 bool clear_site_specific);
54 void SetSitePermission(uint32 request_id,
55 PP_Flash_BrowserOperations_SettingType setting_type,
56 const ppapi::FlashSiteSettings& sites);
[email protected]951ef0b2012-07-27 22:46:5357 void GetSitesWithData(uint32 request_id);
58 void ClearSiteData(uint32 request_id,
59 const std::string& site,
60 uint64 flags,
61 uint64 max_age);
[email protected]1a559442012-05-27 07:18:4662
[email protected]b44f8ad2012-06-15 20:52:5863 // IPC::Listener implementation.
[email protected]1a559442012-05-27 07:18:4664 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
65 virtual void OnChannelError() OVERRIDE;
66
67 private:
68 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>;
69 friend class base::DeleteHelper<Core>;
70
71 enum RequestType {
72 INVALID_REQUEST_TYPE = 0,
[email protected]ee4dd682012-06-12 15:49:3373 DEAUTHORIZE_CONTENT_LICENSES,
74 GET_PERMISSION_SETTINGS,
75 SET_DEFAULT_PERMISSION,
[email protected]951ef0b2012-07-27 22:46:5376 SET_SITE_PERMISSION,
77 GET_SITES_WITH_DATA,
78 CLEAR_SITE_DATA,
[email protected]1a559442012-05-27 07:18:4679 };
80
[email protected]7c826912012-10-01 22:05:2781 enum State {
82 STATE_UNINITIALIZED = 0,
83 STATE_INITIALIZED,
84 STATE_ERROR,
85 STATE_DETACHED,
86 };
87
[email protected]1a559442012-05-27 07:18:4688 struct PendingRequest {
[email protected]ee4dd682012-06-12 15:49:3389 PendingRequest()
90 : id(0),
91 type(INVALID_REQUEST_TYPE),
92 setting_type(PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC),
93 permission(PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT),
[email protected]3695fe32012-08-03 01:55:5994 clear_site_specific(false),
95 flags(0),
96 max_age(0) {
[email protected]ee4dd682012-06-12 15:49:3397 }
[email protected]1a559442012-05-27 07:18:4698
99 uint32 id;
100 RequestType type;
[email protected]ee4dd682012-06-12 15:49:33101
102 // Used by GET_PERMISSION_SETTINGS, SET_DEFAULT_PERMISSION and
103 // SET_SITE_PERMISSION.
104 PP_Flash_BrowserOperations_SettingType setting_type;
105
106 // Used by SET_DEFAULT_PERMISSION.
107 PP_Flash_BrowserOperations_Permission permission;
108 bool clear_site_specific;
109
110 // Used by SET_SITE_PERMISSION.
111 ppapi::FlashSiteSettings sites;
[email protected]951ef0b2012-07-27 22:46:53112
113 // Used by CLEAR_SITE_DATA
114 std::string site;
115 uint64 flags;
116 uint64 max_age;
[email protected]1a559442012-05-27 07:18:46117 };
118
119 virtual ~Core();
120
[email protected]1a559442012-05-27 07:18:46121 void ConnectToChannel(bool success, const IPC::ChannelHandle& handle);
122
[email protected]6464cc12012-07-12 09:25:53123 void InitializeOnIOThread();
[email protected]1a559442012-05-27 07:18:46124 void DeauthorizeContentLicensesOnIOThread(uint32 request_id);
[email protected]ee4dd682012-06-12 15:49:33125 void GetPermissionSettingsOnIOThread(
126 uint32 request_id,
127 PP_Flash_BrowserOperations_SettingType setting_type);
128 void SetDefaultPermissionOnIOThread(
129 uint32 request_id,
130 PP_Flash_BrowserOperations_SettingType setting_type,
131 PP_Flash_BrowserOperations_Permission permission,
132 bool clear_site_specific);
133 void SetSitePermissionOnIOThread(
134 uint32 request_id,
135 PP_Flash_BrowserOperations_SettingType setting_type,
136 const ppapi::FlashSiteSettings& sites);
[email protected]951ef0b2012-07-27 22:46:53137 void GetSitesWithDataOnIOThread(uint32 request_id);
138 void ClearSiteDataOnIOThread(uint32 request_id,
139 const std::string& site,
140 uint64 flags,
141 uint64 max_age);
[email protected]4d4ee4c2012-06-22 19:11:30142 void DetachOnIOThread();
[email protected]ee4dd682012-06-12 15:49:33143
[email protected]1a559442012-05-27 07:18:46144 void NotifyErrorFromIOThread();
145
146 void NotifyDeauthorizeContentLicensesCompleted(uint32 request_id,
147 bool success);
[email protected]ee4dd682012-06-12 15:49:33148 void NotifyGetPermissionSettingsCompleted(
149 uint32 request_id,
150 bool success,
151 PP_Flash_BrowserOperations_Permission default_permission,
152 const ppapi::FlashSiteSettings& sites);
153 void NotifySetDefaultPermissionCompleted(uint32 request_id, bool success);
154 void NotifySetSitePermissionCompleted(uint32 request_id, bool success);
[email protected]951ef0b2012-07-27 22:46:53155 void NotifyGetSitesWithDataCompleted(uint32 request_id,
156 const std::vector<std::string>& sites);
157 void NotifyClearSiteDataCompleted(uint32 request_id, bool success);
[email protected]ee4dd682012-06-12 15:49:33158
[email protected]1a559442012-05-27 07:18:46159 void NotifyError(
160 const std::vector<std::pair<uint32, RequestType> >& notifications);
161
162 // Message handlers.
163 void OnDeauthorizeContentLicensesResult(uint32 request_id, bool success);
[email protected]ee4dd682012-06-12 15:49:33164 void OnGetPermissionSettingsResult(
165 uint32 request_id,
166 bool success,
167 PP_Flash_BrowserOperations_Permission default_permission,
168 const ppapi::FlashSiteSettings& sites);
169 void OnSetDefaultPermissionResult(uint32 request_id, bool success);
170 void OnSetSitePermissionResult(uint32 request_id, bool success);
[email protected]951ef0b2012-07-27 22:46:53171 void OnGetSitesWithDataResult(uint32 request_id,
172 const std::vector<std::string>& sites);
173 void OnClearSiteDataResult(uint32 request_id, bool success);
[email protected]1a559442012-05-27 07:18:46174
175 // Used only on the UI thread.
[email protected]7c826912012-10-01 22:05:27176 base::WeakPtr<PepperFlashSettingsManager> manager_;
[email protected]1a559442012-05-27 07:18:46177
178 // Used only on the I/O thread.
179 FilePath plugin_data_path_;
180
181 // The channel is NULL until we have opened a connection to the broker
182 // process. Used only on the I/O thread.
183 scoped_ptr<IPC::Channel> channel_;
184
185 // Used only on the I/O thread.
[email protected]7c826912012-10-01 22:05:27186 State state_;
[email protected]1a559442012-05-27 07:18:46187
188 // Requests that need to be sent once the channel to the broker process is
189 // established. Used only on the I/O thread.
190 std::vector<PendingRequest> pending_requests_;
191 // Requests that have been sent but haven't got replied. Used only on the
192 // I/O thread.
193 std::map<uint32, RequestType> pending_responses_;
194
195 // Used only on the I/O thread.
196 scoped_refptr<content::PepperFlashSettingsHelper> helper_;
197
198 // Path for the current profile. Must be retrieved on the UI thread from the
199 // browser context when we start so we can use it later on the I/O thread.
200 FilePath browser_context_path_;
201
202 scoped_refptr<PluginPrefs> plugin_prefs_;
203};
204
[email protected]7c826912012-10-01 22:05:27205PepperFlashSettingsManager::Core::Core(
206 base::WeakPtr<PepperFlashSettingsManager> manager,
207 content::BrowserContext* browser_context)
[email protected]1a559442012-05-27 07:18:46208 : manager_(manager),
[email protected]7c826912012-10-01 22:05:27209 state_(STATE_UNINITIALIZED),
[email protected]1a559442012-05-27 07:18:46210 browser_context_path_(browser_context->GetPath()),
211 plugin_prefs_(PluginPrefs::GetForProfile(
212 Profile::FromBrowserContext(browser_context))) {
213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]1a559442012-05-27 07:18:46214}
215
216PepperFlashSettingsManager::Core::~Core() {
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
218}
219
[email protected]6464cc12012-07-12 09:25:53220void PepperFlashSettingsManager::Core::Initialize() {
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
222 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
223 base::Bind(&Core::InitializeOnIOThread, this));
224}
225
[email protected]1a559442012-05-27 07:18:46226void PepperFlashSettingsManager::Core::Detach() {
227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
228
[email protected]7c826912012-10-01 22:05:27229 // This call guarantees that one ref is retained until we get to the DETACHED
230 // state. This is important. Otherwise, if the ref count drops to zero on the
[email protected]4d4ee4c2012-06-22 19:11:30231 // UI thread (which posts a task to delete this object on the I/O thread)
232 // while the I/O thread doesn't know about it, methods on the I/O thread might
233 // increase the ref count again and cause double deletion.
234 BrowserThread::PostTask(
235 BrowserThread::IO, FROM_HERE, base::Bind(&Core::DetachOnIOThread, this));
[email protected]1a559442012-05-27 07:18:46236}
237
238void PepperFlashSettingsManager::Core::DeauthorizeContentLicenses(
239 uint32 request_id) {
240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
241
242 BrowserThread::PostTask(
243 BrowserThread::IO, FROM_HERE,
244 base::Bind(&Core::DeauthorizeContentLicensesOnIOThread, this,
245 request_id));
246}
247
[email protected]ee4dd682012-06-12 15:49:33248void PepperFlashSettingsManager::Core::GetPermissionSettings(
249 uint32 request_id,
250 PP_Flash_BrowserOperations_SettingType setting_type) {
251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
252
253 BrowserThread::PostTask(
254 BrowserThread::IO, FROM_HERE,
255 base::Bind(&Core::GetPermissionSettingsOnIOThread, this, request_id,
256 setting_type));
257}
258
259void PepperFlashSettingsManager::Core::SetDefaultPermission(
260 uint32 request_id,
261 PP_Flash_BrowserOperations_SettingType setting_type,
262 PP_Flash_BrowserOperations_Permission permission,
263 bool clear_site_specific) {
264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
265
266 BrowserThread::PostTask(
267 BrowserThread::IO, FROM_HERE,
268 base::Bind(&Core::SetDefaultPermissionOnIOThread, this, request_id,
269 setting_type, permission, clear_site_specific));
270}
271
272void PepperFlashSettingsManager::Core::SetSitePermission(
[email protected]7c826912012-10-01 22:05:27273 uint32 request_id,
274 PP_Flash_BrowserOperations_SettingType setting_type,
275 const ppapi::FlashSiteSettings& sites) {
[email protected]ee4dd682012-06-12 15:49:33276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
277
278 BrowserThread::PostTask(
279 BrowserThread::IO, FROM_HERE,
280 base::Bind(&Core::SetSitePermissionOnIOThread, this, request_id,
281 setting_type, sites));
282}
283
[email protected]951ef0b2012-07-27 22:46:53284void PepperFlashSettingsManager::Core::GetSitesWithData(uint32 request_id) {
285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
286
287 BrowserThread::PostTask(
288 BrowserThread::IO, FROM_HERE,
289 base::Bind(&Core::GetSitesWithDataOnIOThread, this, request_id));
290}
291
292void PepperFlashSettingsManager::Core::ClearSiteData(uint32 request_id,
293 const std::string& site,
294 uint64 flags,
295 uint64 max_age) {
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
297
298 BrowserThread::PostTask(
299 BrowserThread::IO, FROM_HERE,
300 base::Bind(&Core::ClearSiteDataOnIOThread, this, request_id,
301 site, flags, max_age));
302}
303
[email protected]1a559442012-05-27 07:18:46304bool PepperFlashSettingsManager::Core::OnMessageReceived(
305 const IPC::Message& message) {
306 IPC_BEGIN_MESSAGE_MAP(Core, message)
307 IPC_MESSAGE_HANDLER(PpapiHostMsg_DeauthorizeContentLicensesResult,
308 OnDeauthorizeContentLicensesResult)
[email protected]ee4dd682012-06-12 15:49:33309 IPC_MESSAGE_HANDLER(PpapiHostMsg_GetPermissionSettingsResult,
310 OnGetPermissionSettingsResult)
311 IPC_MESSAGE_HANDLER(PpapiHostMsg_SetDefaultPermissionResult,
312 OnSetDefaultPermissionResult)
313 IPC_MESSAGE_HANDLER(PpapiHostMsg_SetSitePermissionResult,
314 OnSetSitePermissionResult)
[email protected]951ef0b2012-07-27 22:46:53315 IPC_MESSAGE_HANDLER(PpapiHostMsg_GetSitesWithDataResult,
316 OnGetSitesWithDataResult)
317 IPC_MESSAGE_HANDLER(PpapiHostMsg_ClearSiteDataResult,
318 OnClearSiteDataResult)
[email protected]1a559442012-05-27 07:18:46319 IPC_MESSAGE_UNHANDLED_ERROR()
320 IPC_END_MESSAGE_MAP()
321
322 return true;
323}
324
325void PepperFlashSettingsManager::Core::OnChannelError() {
326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27327 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30328 return;
[email protected]1a559442012-05-27 07:18:46329
330 NotifyErrorFromIOThread();
331}
332
[email protected]1a559442012-05-27 07:18:46333void PepperFlashSettingsManager::Core::ConnectToChannel(
334 bool success,
335 const IPC::ChannelHandle& handle) {
336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27337 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30338 return;
339
[email protected]7c826912012-10-01 22:05:27340 DCHECK(state_ == STATE_UNINITIALIZED);
[email protected]1a559442012-05-27 07:18:46341 DCHECK(!channel_.get());
342
343 if (!success) {
[email protected]ee4dd682012-06-12 15:49:33344 DLOG(ERROR) << "Couldn't open plugin channel";
[email protected]1a559442012-05-27 07:18:46345 NotifyErrorFromIOThread();
346 return;
347 }
348
349 channel_.reset(new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this));
350 if (!channel_->Connect()) {
[email protected]ee4dd682012-06-12 15:49:33351 DLOG(ERROR) << "Couldn't connect to plugin";
[email protected]1a559442012-05-27 07:18:46352 NotifyErrorFromIOThread();
353 return;
354 }
355
[email protected]7c826912012-10-01 22:05:27356 state_ = STATE_INITIALIZED;
[email protected]1a559442012-05-27 07:18:46357
358 std::vector<PendingRequest> temp_pending_requests;
359 temp_pending_requests.swap(pending_requests_);
360 for (std::vector<PendingRequest>::iterator iter =
361 temp_pending_requests.begin();
362 iter != temp_pending_requests.end(); ++iter) {
363 switch (iter->type) {
[email protected]951ef0b2012-07-27 22:46:53364 case INVALID_REQUEST_TYPE:
365 NOTREACHED();
366 break;
[email protected]1a559442012-05-27 07:18:46367 case DEAUTHORIZE_CONTENT_LICENSES:
368 DeauthorizeContentLicensesOnIOThread(iter->id);
369 break;
[email protected]ee4dd682012-06-12 15:49:33370 case GET_PERMISSION_SETTINGS:
371 GetPermissionSettingsOnIOThread(iter->id, iter->setting_type);
372 break;
373 case SET_DEFAULT_PERMISSION:
374 SetDefaultPermissionOnIOThread(
375 iter->id, iter->setting_type, iter->permission,
376 iter->clear_site_specific);
377 break;
378 case SET_SITE_PERMISSION:
379 SetSitePermissionOnIOThread(iter->id, iter->setting_type, iter->sites);
380 break;
[email protected]951ef0b2012-07-27 22:46:53381 case GET_SITES_WITH_DATA:
382 GetSitesWithDataOnIOThread(iter->id);
383 break;
384 case CLEAR_SITE_DATA:
385 ClearSiteDataOnIOThread(iter->id, iter->site, iter->flags,
386 iter->max_age);
[email protected]1a559442012-05-27 07:18:46387 break;
388 }
389 }
390}
391
[email protected]6464cc12012-07-12 09:25:53392void PepperFlashSettingsManager::Core::InitializeOnIOThread() {
393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27394 DCHECK_EQ(STATE_UNINITIALIZED, state_);
[email protected]6464cc12012-07-12 09:25:53395
396 webkit::WebPluginInfo plugin_info;
397 if (!PepperFlashSettingsManager::IsPepperFlashInUse(plugin_prefs_.get(),
398 &plugin_info)) {
399 NotifyErrorFromIOThread();
400 return;
401 }
402
403 FilePath profile_path =
404 browser_context_path_.Append(content::kPepperDataDirname);
405#if defined(OS_WIN)
406 plugin_data_path_ = profile_path.Append(plugin_info.name);
407#else
408 plugin_data_path_ = profile_path.Append(UTF16ToUTF8(plugin_info.name));
409#endif
410
411 helper_ = content::PepperFlashSettingsHelper::Create();
412 content::PepperFlashSettingsHelper::OpenChannelCallback callback =
413 base::Bind(&Core::ConnectToChannel, this);
414 helper_->OpenChannelToBroker(plugin_info.path, callback);
415}
416
[email protected]1a559442012-05-27 07:18:46417void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread(
418 uint32 request_id) {
419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27420 DCHECK_NE(STATE_DETACHED, state_);
[email protected]1a559442012-05-27 07:18:46421
[email protected]7c826912012-10-01 22:05:27422 if (state_ == STATE_UNINITIALIZED) {
[email protected]1a559442012-05-27 07:18:46423 PendingRequest request;
424 request.id = request_id;
425 request.type = DEAUTHORIZE_CONTENT_LICENSES;
426 pending_requests_.push_back(request);
427 return;
428 }
429
430 pending_responses_.insert(
431 std::make_pair(request_id, DEAUTHORIZE_CONTENT_LICENSES));
[email protected]7c826912012-10-01 22:05:27432 if (state_ == STATE_ERROR) {
433 NotifyErrorFromIOThread();
434 return;
435 }
436
[email protected]1a559442012-05-27 07:18:46437 IPC::Message* msg =
438 new PpapiMsg_DeauthorizeContentLicenses(request_id, plugin_data_path_);
439 if (!channel_->Send(msg)) {
[email protected]ee4dd682012-06-12 15:49:33440 DLOG(ERROR) << "Couldn't send DeauthorizeContentLicenses message";
441 // A failure notification for the current request will be sent since
442 // |pending_responses_| has been updated.
443 NotifyErrorFromIOThread();
444 }
445}
446
447void PepperFlashSettingsManager::Core::GetPermissionSettingsOnIOThread(
448 uint32 request_id,
449 PP_Flash_BrowserOperations_SettingType setting_type) {
450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27451 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33452
[email protected]7c826912012-10-01 22:05:27453 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33454 PendingRequest request;
455 request.id = request_id;
456 request.type = GET_PERMISSION_SETTINGS;
457 request.setting_type = setting_type;
458 pending_requests_.push_back(request);
459 return;
460 }
461
462 pending_responses_.insert(
463 std::make_pair(request_id, GET_PERMISSION_SETTINGS));
[email protected]7c826912012-10-01 22:05:27464 if (state_ == STATE_ERROR) {
465 NotifyErrorFromIOThread();
466 return;
467 }
468
[email protected]ee4dd682012-06-12 15:49:33469 IPC::Message* msg = new PpapiMsg_GetPermissionSettings(
470 request_id, plugin_data_path_, setting_type);
471 if (!channel_->Send(msg)) {
472 DLOG(ERROR) << "Couldn't send GetPermissionSettings message";
473 // A failure notification for the current request will be sent since
474 // |pending_responses_| has been updated.
475 NotifyErrorFromIOThread();
476 }
477}
478
479void PepperFlashSettingsManager::Core::SetDefaultPermissionOnIOThread(
480 uint32 request_id,
481 PP_Flash_BrowserOperations_SettingType setting_type,
482 PP_Flash_BrowserOperations_Permission permission,
483 bool clear_site_specific) {
484 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27485 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33486
[email protected]7c826912012-10-01 22:05:27487 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33488 PendingRequest request;
489 request.id = request_id;
490 request.type = SET_DEFAULT_PERMISSION;
491 request.setting_type = setting_type;
492 request.permission = permission;
493 request.clear_site_specific = clear_site_specific;
494 pending_requests_.push_back(request);
495 return;
496 }
497
498 pending_responses_.insert(std::make_pair(request_id, SET_DEFAULT_PERMISSION));
[email protected]7c826912012-10-01 22:05:27499 if (state_ == STATE_ERROR) {
500 NotifyErrorFromIOThread();
501 return;
502 }
503
[email protected]ee4dd682012-06-12 15:49:33504 IPC::Message* msg = new PpapiMsg_SetDefaultPermission(
505 request_id, plugin_data_path_, setting_type, permission,
506 clear_site_specific);
507 if (!channel_->Send(msg)) {
508 DLOG(ERROR) << "Couldn't send SetDefaultPermission message";
509 // A failure notification for the current request will be sent since
510 // |pending_responses_| has been updated.
511 NotifyErrorFromIOThread();
512 }
513}
514
515void PepperFlashSettingsManager::Core::SetSitePermissionOnIOThread(
516 uint32 request_id,
517 PP_Flash_BrowserOperations_SettingType setting_type,
518 const ppapi::FlashSiteSettings& sites) {
519 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27520 DCHECK_NE(STATE_DETACHED, state_);
[email protected]ee4dd682012-06-12 15:49:33521
[email protected]7c826912012-10-01 22:05:27522 if (state_ == STATE_UNINITIALIZED) {
[email protected]ee4dd682012-06-12 15:49:33523 pending_requests_.push_back(PendingRequest());
524 PendingRequest& request = pending_requests_.back();
525 request.id = request_id;
526 request.type = SET_SITE_PERMISSION;
527 request.setting_type = setting_type;
528 request.sites = sites;
529 return;
530 }
531
532 pending_responses_.insert(std::make_pair(request_id, SET_SITE_PERMISSION));
[email protected]7c826912012-10-01 22:05:27533 if (state_ == STATE_ERROR) {
534 NotifyErrorFromIOThread();
535 return;
536 }
537
[email protected]ee4dd682012-06-12 15:49:33538 IPC::Message* msg = new PpapiMsg_SetSitePermission(
539 request_id, plugin_data_path_, setting_type, sites);
540 if (!channel_->Send(msg)) {
541 DLOG(ERROR) << "Couldn't send SetSitePermission message";
[email protected]1a559442012-05-27 07:18:46542 // A failure notification for the current request will be sent since
543 // |pending_responses_| has been updated.
544 NotifyErrorFromIOThread();
545 }
546}
547
[email protected]951ef0b2012-07-27 22:46:53548void PepperFlashSettingsManager::Core::GetSitesWithDataOnIOThread(
549 uint32 request_id) {
550 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27551 DCHECK_NE(STATE_DETACHED, state_);
[email protected]951ef0b2012-07-27 22:46:53552
[email protected]7c826912012-10-01 22:05:27553 if (state_ == STATE_UNINITIALIZED) {
[email protected]951ef0b2012-07-27 22:46:53554 pending_requests_.push_back(PendingRequest());
555 PendingRequest& request = pending_requests_.back();
556 request.id = request_id;
557 request.type = GET_SITES_WITH_DATA;
558 return;
559 }
560
561 pending_responses_.insert(std::make_pair(request_id, GET_SITES_WITH_DATA));
[email protected]7c826912012-10-01 22:05:27562 if (state_ == STATE_ERROR) {
563 NotifyErrorFromIOThread();
564 return;
565 }
566
[email protected]951ef0b2012-07-27 22:46:53567 IPC::Message* msg = new PpapiMsg_GetSitesWithData(
568 request_id, plugin_data_path_);
569 if (!channel_->Send(msg)) {
570 DLOG(ERROR) << "Couldn't send GetSitesWithData message";
571 // A failure notification for the current request will be sent since
572 // |pending_responses_| has been updated.
573 NotifyErrorFromIOThread();
574 }
575}
576
577void PepperFlashSettingsManager::Core::ClearSiteDataOnIOThread(
578 uint32 request_id,
579 const std::string& site,
580 uint64 flags,
581 uint64 max_age) {
582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27583 DCHECK_NE(STATE_DETACHED, state_);
[email protected]951ef0b2012-07-27 22:46:53584
[email protected]7c826912012-10-01 22:05:27585 if (state_ == STATE_UNINITIALIZED) {
[email protected]951ef0b2012-07-27 22:46:53586 pending_requests_.push_back(PendingRequest());
587 PendingRequest& request = pending_requests_.back();
588 request.id = request_id;
589 request.type = CLEAR_SITE_DATA;
590 request.site = site;
591 request.flags = flags;
592 request.max_age = max_age;
593 return;
594 }
595
596 pending_responses_.insert(std::make_pair(request_id, CLEAR_SITE_DATA));
[email protected]7c826912012-10-01 22:05:27597 if (state_ == STATE_ERROR) {
598 NotifyErrorFromIOThread();
599 return;
600 }
601
[email protected]951ef0b2012-07-27 22:46:53602 IPC::Message* msg = new PpapiMsg_ClearSiteData(
603 request_id, plugin_data_path_, site, flags, max_age);
604 if (!channel_->Send(msg)) {
605 DLOG(ERROR) << "Couldn't send ClearSiteData message";
606 // A failure notification for the current request will be sent since
607 // |pending_responses_| has been updated.
608 NotifyErrorFromIOThread();
609 }
610}
611
[email protected]4d4ee4c2012-06-22 19:11:30612void PepperFlashSettingsManager::Core::DetachOnIOThread() {
[email protected]7c826912012-10-01 22:05:27613 state_ = STATE_DETACHED;
[email protected]4d4ee4c2012-06-22 19:11:30614}
615
[email protected]1a559442012-05-27 07:18:46616void PepperFlashSettingsManager::Core::NotifyErrorFromIOThread() {
617 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27618 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30619 return;
[email protected]1a559442012-05-27 07:18:46620
[email protected]7c826912012-10-01 22:05:27621 state_ = STATE_ERROR;
[email protected]1a559442012-05-27 07:18:46622 std::vector<std::pair<uint32, RequestType> > notifications;
623 for (std::vector<PendingRequest>::iterator iter = pending_requests_.begin();
624 iter != pending_requests_.end(); ++iter) {
625 notifications.push_back(std::make_pair(iter->id, iter->type));
626 }
627 pending_requests_.clear();
628 notifications.insert(notifications.end(), pending_responses_.begin(),
629 pending_responses_.end());
630 pending_responses_.clear();
631
632 BrowserThread::PostTask(
633 BrowserThread::UI, FROM_HERE,
634 base::Bind(&Core::NotifyError, this, notifications));
635}
636
637void
638PepperFlashSettingsManager::Core::NotifyDeauthorizeContentLicensesCompleted(
639 uint32 request_id,
640 bool success) {
641 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
642
[email protected]7c826912012-10-01 22:05:27643 if (manager_.get()) {
[email protected]1a559442012-05-27 07:18:46644 manager_->client_->OnDeauthorizeContentLicensesCompleted(
645 request_id, success);
646 }
647}
648
[email protected]ee4dd682012-06-12 15:49:33649void PepperFlashSettingsManager::Core::NotifyGetPermissionSettingsCompleted(
650 uint32 request_id,
651 bool success,
652 PP_Flash_BrowserOperations_Permission default_permission,
653 const ppapi::FlashSiteSettings& sites) {
654 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
655
[email protected]7c826912012-10-01 22:05:27656 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33657 manager_->client_->OnGetPermissionSettingsCompleted(
658 request_id, success, default_permission, sites);
659 }
660}
661
662void PepperFlashSettingsManager::Core::NotifySetDefaultPermissionCompleted(
663 uint32 request_id,
664 bool success) {
665 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
666
[email protected]7c826912012-10-01 22:05:27667 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33668 manager_->client_->OnSetDefaultPermissionCompleted(
669 request_id, success);
670 }
671}
672
673void PepperFlashSettingsManager::Core::NotifySetSitePermissionCompleted(
674 uint32 request_id,
675 bool success) {
676 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
677
[email protected]7c826912012-10-01 22:05:27678 if (manager_.get()) {
[email protected]ee4dd682012-06-12 15:49:33679 manager_->client_->OnSetSitePermissionCompleted(
680 request_id, success);
681 }
682}
683
[email protected]951ef0b2012-07-27 22:46:53684void PepperFlashSettingsManager::Core::NotifyGetSitesWithDataCompleted(
685 uint32 request_id,
686 const std::vector<std::string>& sites) {
687 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
688
[email protected]7c826912012-10-01 22:05:27689 if (manager_.get()) {
[email protected]951ef0b2012-07-27 22:46:53690 manager_->client_->OnGetSitesWithDataCompleted(
691 request_id, sites);
692 }
693}
694
695void PepperFlashSettingsManager::Core::NotifyClearSiteDataCompleted(
696 uint32 request_id,
697 bool success) {
698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
699
[email protected]7c826912012-10-01 22:05:27700 if (manager_.get())
[email protected]951ef0b2012-07-27 22:46:53701 manager_->client_->OnClearSiteDataCompleted(request_id, success);
702}
703
[email protected]1a559442012-05-27 07:18:46704void PepperFlashSettingsManager::Core::NotifyError(
705 const std::vector<std::pair<uint32, RequestType> >& notifications) {
706 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
707
708 scoped_refptr<Core> protector(this);
709 for (std::vector<std::pair<uint32, RequestType> >::const_iterator iter =
710 notifications.begin(); iter != notifications.end(); ++iter) {
[email protected]7c826912012-10-01 22:05:27711 // Check |manager_| for each iteration in case it is destroyed in one of
[email protected]1a559442012-05-27 07:18:46712 // the callbacks.
[email protected]7c826912012-10-01 22:05:27713 if (!manager_.get())
[email protected]951ef0b2012-07-27 22:46:53714 return;
715
716 switch (iter->second) {
717 case INVALID_REQUEST_TYPE:
718 NOTREACHED();
719 break;
720 case DEAUTHORIZE_CONTENT_LICENSES:
721 manager_->client_->OnDeauthorizeContentLicensesCompleted(
722 iter->first, false);
723 break;
724 case GET_PERMISSION_SETTINGS:
725 manager_->client_->OnGetPermissionSettingsCompleted(
726 iter->first, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT,
727 ppapi::FlashSiteSettings());
728 break;
729 case SET_DEFAULT_PERMISSION:
730 manager_->client_->OnSetDefaultPermissionCompleted(
731 iter->first, false);
732 break;
733 case SET_SITE_PERMISSION:
734 manager_->client_->OnSetSitePermissionCompleted(iter->first, false);
735 break;
736 case GET_SITES_WITH_DATA:
737 manager_->client_->OnGetSitesWithDataCompleted(
738 iter->first, std::vector<std::string>());
739 break;
740 case CLEAR_SITE_DATA:
741 manager_->client_->OnClearSiteDataCompleted(iter->first, false);
742 break;
[email protected]1a559442012-05-27 07:18:46743 }
744 }
745
[email protected]7c826912012-10-01 22:05:27746 if (manager_.get())
747 manager_->OnError(this);
[email protected]1a559442012-05-27 07:18:46748}
749
750void PepperFlashSettingsManager::Core::OnDeauthorizeContentLicensesResult(
751 uint32 request_id,
752 bool success) {
753 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27754 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30755 return;
756
[email protected]ee4dd682012-06-12 15:49:33757 DLOG_IF(ERROR, !success) << "DeauthorizeContentLicenses returned error";
[email protected]1a559442012-05-27 07:18:46758
759 std::map<uint32, RequestType>::iterator iter =
760 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53761 if (iter == pending_responses_.end())
762 return;
[email protected]1a559442012-05-27 07:18:46763
[email protected]951ef0b2012-07-27 22:46:53764 DCHECK_EQ(iter->second, DEAUTHORIZE_CONTENT_LICENSES);
765
766 pending_responses_.erase(iter);
767 BrowserThread::PostTask(
768 BrowserThread::UI, FROM_HERE,
769 base::Bind(&Core::NotifyDeauthorizeContentLicensesCompleted, this,
770 request_id, success));
[email protected]1a559442012-05-27 07:18:46771}
772
[email protected]ee4dd682012-06-12 15:49:33773void PepperFlashSettingsManager::Core::OnGetPermissionSettingsResult(
774 uint32 request_id,
775 bool success,
776 PP_Flash_BrowserOperations_Permission default_permission,
777 const ppapi::FlashSiteSettings& sites) {
778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27779 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30780 return;
781
[email protected]ee4dd682012-06-12 15:49:33782 DLOG_IF(ERROR, !success) << "GetPermissionSettings returned error";
783
784 std::map<uint32, RequestType>::iterator iter =
785 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53786 if (iter == pending_responses_.end())
787 return;
[email protected]ee4dd682012-06-12 15:49:33788
[email protected]951ef0b2012-07-27 22:46:53789 DCHECK_EQ(iter->second, GET_PERMISSION_SETTINGS);
790
791 pending_responses_.erase(iter);
792 BrowserThread::PostTask(
793 BrowserThread::UI, FROM_HERE,
794 base::Bind(&Core::NotifyGetPermissionSettingsCompleted, this,
795 request_id, success, default_permission, sites));
[email protected]ee4dd682012-06-12 15:49:33796}
797
798void PepperFlashSettingsManager::Core::OnSetDefaultPermissionResult(
799 uint32 request_id,
800 bool success) {
801 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27802 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30803 return;
804
[email protected]ee4dd682012-06-12 15:49:33805 DLOG_IF(ERROR, !success) << "SetDefaultPermission returned error";
806
807 std::map<uint32, RequestType>::iterator iter =
808 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53809 if (iter == pending_responses_.end())
810 return;
[email protected]ee4dd682012-06-12 15:49:33811
[email protected]951ef0b2012-07-27 22:46:53812 DCHECK_EQ(iter->second, SET_DEFAULT_PERMISSION);
813
814 pending_responses_.erase(iter);
815 BrowserThread::PostTask(
816 BrowserThread::UI, FROM_HERE,
817 base::Bind(&Core::NotifySetDefaultPermissionCompleted, this,
818 request_id, success));
[email protected]ee4dd682012-06-12 15:49:33819}
820
821void PepperFlashSettingsManager::Core::OnSetSitePermissionResult(
822 uint32 request_id,
823 bool success) {
824 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27825 if (state_ == STATE_DETACHED)
[email protected]4d4ee4c2012-06-22 19:11:30826 return;
827
[email protected]ee4dd682012-06-12 15:49:33828 DLOG_IF(ERROR, !success) << "SetSitePermission returned error";
829
830 std::map<uint32, RequestType>::iterator iter =
831 pending_responses_.find(request_id);
[email protected]951ef0b2012-07-27 22:46:53832 if (iter == pending_responses_.end())
833 return;
[email protected]ee4dd682012-06-12 15:49:33834
[email protected]951ef0b2012-07-27 22:46:53835 DCHECK_EQ(iter->second, SET_SITE_PERMISSION);
836
837 pending_responses_.erase(iter);
838 BrowserThread::PostTask(
839 BrowserThread::UI, FROM_HERE,
840 base::Bind(&Core::NotifySetSitePermissionCompleted, this, request_id,
841 success));
842}
843
844void PepperFlashSettingsManager::Core::OnGetSitesWithDataResult(
845 uint32 request_id,
846 const std::vector<std::string>& sites) {
847 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27848 if (state_ == STATE_DETACHED)
[email protected]951ef0b2012-07-27 22:46:53849 return;
850
851 std::map<uint32, RequestType>::iterator iter =
852 pending_responses_.find(request_id);
853 if (iter == pending_responses_.end())
854 return;
855
856 DCHECK_EQ(iter->second, GET_SITES_WITH_DATA);
857
858 pending_responses_.erase(iter);
859 BrowserThread::PostTask(
860 BrowserThread::UI, FROM_HERE,
861 base::Bind(&Core::NotifyGetSitesWithDataCompleted, this, request_id,
862 sites));
863}
864
865void PepperFlashSettingsManager::Core::OnClearSiteDataResult(
866 uint32 request_id,
867 bool success) {
868 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]7c826912012-10-01 22:05:27869 if (state_ == STATE_DETACHED)
[email protected]951ef0b2012-07-27 22:46:53870 return;
871
872 DLOG_IF(ERROR, !success) << "ClearSiteData returned error";
873
874 std::map<uint32, RequestType>::iterator iter =
875 pending_responses_.find(request_id);
876 if (iter == pending_responses_.end())
877 return;
878
879 DCHECK_EQ(iter->second, CLEAR_SITE_DATA);
880
881 pending_responses_.erase(iter);
882 BrowserThread::PostTask(
883 BrowserThread::UI, FROM_HERE,
884 base::Bind(&Core::NotifyClearSiteDataCompleted, this, request_id,
885 success));
[email protected]ee4dd682012-06-12 15:49:33886}
887
[email protected]1a559442012-05-27 07:18:46888PepperFlashSettingsManager::PepperFlashSettingsManager(
889 Client* client,
890 content::BrowserContext* browser_context)
[email protected]7c826912012-10-01 22:05:27891 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
892 client_(client),
[email protected]1a559442012-05-27 07:18:46893 browser_context_(browser_context),
894 next_request_id_(1) {
895 DCHECK(client);
896 DCHECK(browser_context);
897}
898
899PepperFlashSettingsManager::~PepperFlashSettingsManager() {
[email protected]951ef0b2012-07-27 22:46:53900 if (core_.get())
[email protected]1a559442012-05-27 07:18:46901 core_->Detach();
[email protected]1a559442012-05-27 07:18:46902}
903
[email protected]18a4d63c82012-05-25 23:37:03904// static
905bool PepperFlashSettingsManager::IsPepperFlashInUse(
906 PluginPrefs* plugin_prefs,
907 webkit::WebPluginInfo* plugin_info) {
908 if (!plugin_prefs)
909 return false;
910
911 content::PluginService* plugin_service =
912 content::PluginService::GetInstance();
913 std::vector<webkit::WebPluginInfo> plugins;
914 plugin_service->GetPluginInfoArray(
915 GURL(), kFlashPluginSwfMimeType, false, &plugins, NULL);
916
917 for (std::vector<webkit::WebPluginInfo>::iterator iter = plugins.begin();
918 iter != plugins.end(); ++iter) {
919 if (webkit::IsPepperPlugin(*iter) && plugin_prefs->IsPluginEnabled(*iter)) {
920 if (plugin_info)
921 *plugin_info = *iter;
922 return true;
923 }
924 }
925 return false;
926}
927
928// static
929void PepperFlashSettingsManager::RegisterUserPrefs(PrefService* prefs) {
930 prefs->RegisterBooleanPref(prefs::kDeauthorizeContentLicenses,
931 false,
932 PrefService::UNSYNCABLE_PREF);
933
934 prefs->RegisterBooleanPref(prefs::kPepperFlashSettingsEnabled,
935 true,
936 PrefService::UNSYNCABLE_PREF);
937}
[email protected]1a559442012-05-27 07:18:46938
939uint32 PepperFlashSettingsManager::DeauthorizeContentLicenses() {
940 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
941
942 EnsureCoreExists();
943 uint32 id = GetNextRequestId();
944 core_->DeauthorizeContentLicenses(id);
945 return id;
946}
947
[email protected]ee4dd682012-06-12 15:49:33948uint32 PepperFlashSettingsManager::GetPermissionSettings(
949 PP_Flash_BrowserOperations_SettingType setting_type) {
950 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
951
952 EnsureCoreExists();
953 uint32 id = GetNextRequestId();
954 core_->GetPermissionSettings(id, setting_type);
955 return id;
956}
957
958uint32 PepperFlashSettingsManager::SetDefaultPermission(
959 PP_Flash_BrowserOperations_SettingType setting_type,
960 PP_Flash_BrowserOperations_Permission permission,
961 bool clear_site_specific) {
962 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
963
964 EnsureCoreExists();
965 uint32 id = GetNextRequestId();
966 core_->SetDefaultPermission(id, setting_type, permission,
967 clear_site_specific);
968 return id;
969}
970
971uint32 PepperFlashSettingsManager::SetSitePermission(
972 PP_Flash_BrowserOperations_SettingType setting_type,
973 const ppapi::FlashSiteSettings& sites) {
974 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
975
976 EnsureCoreExists();
977 uint32 id = GetNextRequestId();
978 core_->SetSitePermission(id, setting_type, sites);
979 return id;
980}
981
[email protected]951ef0b2012-07-27 22:46:53982uint32 PepperFlashSettingsManager::GetSitesWithData() {
983 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
984
985 EnsureCoreExists();
986 uint32 id = GetNextRequestId();
987 core_->GetSitesWithData(id);
988 return id;
989}
990
991uint32 PepperFlashSettingsManager::ClearSiteData(const std::string& site,
992 uint64 flags,
993 uint64 max_age) {
994 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
995
996 EnsureCoreExists();
997 uint32 id = GetNextRequestId();
998 core_->ClearSiteData(id, site, flags, max_age);
999 return id;
1000}
1001
[email protected]1a559442012-05-27 07:18:461002uint32 PepperFlashSettingsManager::GetNextRequestId() {
1003 return next_request_id_++;
1004}
1005
1006void PepperFlashSettingsManager::EnsureCoreExists() {
[email protected]6464cc12012-07-12 09:25:531007 if (!core_.get()) {
[email protected]7c826912012-10-01 22:05:271008 core_ = new Core(weak_ptr_factory_.GetWeakPtr(), browser_context_);
[email protected]6464cc12012-07-12 09:25:531009 core_->Initialize();
1010 }
[email protected]1a559442012-05-27 07:18:461011}
1012
[email protected]7c826912012-10-01 22:05:271013void PepperFlashSettingsManager::OnError(Core* core) {
1014 DCHECK(core);
1015 if (core != core_.get())
1016 return;
[email protected]1a559442012-05-27 07:18:461017
[email protected]7c826912012-10-01 22:05:271018 core_->Detach();
1019 core_ = NULL;
1020}