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

Side by Side Diff: chrome/browser/renderer_host/pepper/pepper_flash_device_id_host.cc

Issue 10909138: Convert the async device ID getter to a chrome resource host (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 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
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 #include "chrome/browser/renderer_host/pepper/pepper_flash_device_id_host.h"
6
7 #include "base/bind.h"
8 #include "base/compiler_specific.h"
9 #include "base/file_util.h"
10 #include "base/logging.h"
11 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/browser_ppapi_host.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/render_view_host.h"
16 #include "ppapi/c/pp_errors.h"
17 #include "ppapi/host/dispatch_host_message.h"
18 #include "ppapi/host/host_message_context.h"
19 #include "ppapi/host/ppapi_host.h"
20 #include "ppapi/proxy/ppapi_messages.h"
21
22 using content::BrowserPpapiHost;
23 using content::BrowserThread;
24
25 namespace chrome {
26
27 namespace {
28
29 // The path to the file containing the DRM ID.
30 // It is mirrored from
31 // chrome/browser/chromeos/system/drm_settings.cc
32 const char kDRMIdentifierFile[] = "Pepper DRM ID.0";
33
34 } // namespace
35
36 // PepperFlashDeviceIDHost::Fetcher --------------------------------------------
37
38 PepperFlashDeviceIDHost::Fetcher::Fetcher(
39 const base::WeakPtr<PepperFlashDeviceIDHost>& host)
40 : host_(host) {
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
42 }
43
44 PepperFlashDeviceIDHost::Fetcher::~Fetcher() {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
46 }
47
48 void PepperFlashDeviceIDHost::Fetcher::Start(BrowserPpapiHost* browser_host) {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
50
51 content::BrowserPpapiHost::RenderViewIDs ids =
52 browser_host->GetRenderViewIDsForInstance(host_->pp_instance());
53 BrowserThread::PostTask(
54 BrowserThread::UI, FROM_HERE,
55 base::Bind(&PepperFlashDeviceIDHost::Fetcher::GetFilePathOnUIThread,
56 this, ids.process_id, ids.view_id));
57 }
58
59 void PepperFlashDeviceIDHost::Fetcher::GetFilePathOnUIThread(
60 int render_process_id,
61 int render_view_id) {
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
63
64 FilePath path;
65 content::RenderViewHost* render_view_host =
66 content::RenderViewHost::FromID(render_process_id, render_view_id);
67 if (render_view_host) {
68 content::BrowserContext* browser_context =
69 render_view_host->GetProcess()->GetBrowserContext();
70 // Don't use DRM IDs when incognito to prevent tracking.
71 if (!browser_context->IsOffTheRecord())
72 path = browser_context->GetPath().AppendASCII(kDRMIdentifierFile);
73 }
74
75 // Continue on the file thread (on failure/incognito, this will just send
76 // the empty path which will forward the error).
77 BrowserThread::PostTask(
78 BrowserThread::FILE, FROM_HERE,
79 base::Bind(&PepperFlashDeviceIDHost::Fetcher::ReadDRMFileOnFileThread,
80 this, path));
81 }
82
83 void PepperFlashDeviceIDHost::Fetcher::ReadDRMFileOnFileThread(
84 const FilePath& path) {
85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
86
87 std::string contents;
88 if (!path.empty())
89 file_util::ReadFileToString(path, &contents);
90
91 // Give back to the resource host on the IO thread. On failure this will just
92 // forward the empty string.
93 BrowserThread::PostTask(
94 BrowserThread::IO, FROM_HERE,
95 base::Bind(&PepperFlashDeviceIDHost::Fetcher::ReplyOnIOThread,
96 this, contents));
97 }
98
99 void PepperFlashDeviceIDHost::Fetcher::ReplyOnIOThread(
100 const std::string& contents) {
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
102 if (host_.get()) // Plugin or resource could have been deleted.
103 host_->GotDRMContents(contents);
104 }
105
106 // PepperFlashDeviceIDHost -----------------------------------------------------
107
108 PepperFlashDeviceIDHost::PepperFlashDeviceIDHost(BrowserPpapiHost* host,
109 PP_Instance instance,
110 PP_Resource resource)
111 : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource),
112 factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
113 browser_ppapi_host_(host) {
114 }
115
116 PepperFlashDeviceIDHost::~PepperFlashDeviceIDHost() {
117 }
118
119 int32_t PepperFlashDeviceIDHost::OnResourceMessageReceived(
120 const IPC::Message& msg,
121 ppapi::host::HostMessageContext* context) {
122 IPC_BEGIN_MESSAGE_MAP(PepperFlashDeviceIDHost, msg)
123 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FlashDeviceID_GetDeviceID,
124 OnHostMsgGetDeviceID)
125 IPC_END_MESSAGE_MAP()
126 return PP_ERROR_FAILED;
127 }
128
129 int32_t PepperFlashDeviceIDHost::OnHostMsgGetDeviceID(
130 const ppapi::host::HostMessageContext* context) {
131 if (fetcher_)
132 return PP_ERROR_INPROGRESS;
133
134 fetcher_ = new Fetcher(factory_.GetWeakPtr());
135 fetcher_->Start(browser_ppapi_host_);
136 reply_params_ = context->MakeReplyParams();
137 return PP_OK_COMPLETIONPENDING;
138 }
139
140 void PepperFlashDeviceIDHost::GotDRMContents(const std::string& contents) {
141 fetcher_ = NULL;
142 reply_params_.set_result(contents.empty() ? PP_ERROR_FAILED : PP_OK);
143 host()->SendReply(reply_params_,
144 PpapiPluginMsg_FlashDeviceID_GetDeviceIDReply(contents));
145 }
146
147 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698