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

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 int process_id = 0;
52 int view_id = 0;
53 browser_host->GetRenderViewIDsForInstance(host_->pp_instance(),
54 &process_id,
55 &view_id);
56 BrowserThread::PostTask(
57 BrowserThread::UI, FROM_HERE,
58 base::Bind(&PepperFlashDeviceIDHost::Fetcher::GetFilePathOnUIThread,
59 this, process_id, view_id));
60 }
61
62 void PepperFlashDeviceIDHost::Fetcher::GetFilePathOnUIThread(
63 int render_process_id,
64 int render_view_id) {
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
66
67 FilePath path;
68 content::RenderViewHost* render_view_host =
69 content::RenderViewHost::FromID(render_process_id, render_view_id);
70 if (render_view_host) {
71 content::BrowserContext* browser_context =
72 render_view_host->GetProcess()->GetBrowserContext();
73 // Don't use DRM IDs when incognito to prevent tracking.
74 if (!browser_context->IsOffTheRecord())
75 path = browser_context->GetPath().AppendASCII(kDRMIdentifierFile);
76 }
77
78 // Continue on the file thread (on failure/incognito, this will just send
79 // the empty path which will forward the error).
80 BrowserThread::PostTask(
81 BrowserThread::FILE, FROM_HERE,
82 base::Bind(&PepperFlashDeviceIDHost::Fetcher::ReadDRMFileOnFileThread,
83 this, path));
84 }
85
86 void PepperFlashDeviceIDHost::Fetcher::ReadDRMFileOnFileThread(
87 const FilePath& path) {
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
89
90 std::string contents;
91 if (!path.empty())
92 file_util::ReadFileToString(path, &contents);
93
94 // Give back to the resource host on the IO thread. On failure this will just
95 // forward the empty string.
96 BrowserThread::PostTask(
97 BrowserThread::IO, FROM_HERE,
98 base::Bind(&PepperFlashDeviceIDHost::Fetcher::ReplyOnIOThread,
99 this, contents));
100 }
101
102 void PepperFlashDeviceIDHost::Fetcher::ReplyOnIOThread(
103 const std::string& contents) {
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
105 if (host_.get()) // Plugin or resource could have been deleted.
106 host_->GotDRMContents(contents);
107 }
108
109 // PepperFlashDeviceIDHost -----------------------------------------------------
110
111 PepperFlashDeviceIDHost::PepperFlashDeviceIDHost(BrowserPpapiHost* host,
112 PP_Instance instance,
113 PP_Resource resource)
114 : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource),
115 factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
116 browser_ppapi_host_(host) {
117 }
118
119 PepperFlashDeviceIDHost::~PepperFlashDeviceIDHost() {
120 }
121
122 int32_t PepperFlashDeviceIDHost::OnResourceMessageReceived(
123 const IPC::Message& msg,
124 ppapi::host::HostMessageContext* context) {
125 IPC_BEGIN_MESSAGE_MAP(PepperFlashDeviceIDHost, msg)
126 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FlashDeviceID_GetDeviceID,
127 OnHostMsgGetDeviceID)
128 IPC_END_MESSAGE_MAP()
129 return PP_ERROR_FAILED;
130 }
131
132 int32_t PepperFlashDeviceIDHost::OnHostMsgGetDeviceID(
133 const ppapi::host::HostMessageContext* context) {
134 if (fetcher_)
135 return PP_ERROR_INPROGRESS;
136
137 fetcher_ = new Fetcher(factory_.GetWeakPtr());
138 fetcher_->Start(browser_ppapi_host_);
139 reply_params_ = context->MakeReplyParams();
140 return PP_OK_COMPLETIONPENDING;
141 }
142
143 void PepperFlashDeviceIDHost::GotDRMContents(const std::string& contents) {
144 fetcher_ = NULL;
145 reply_params_.set_result(contents.empty() ? PP_ERROR_FAILED : PP_OK);
146 host()->SendReply(reply_params_,
147 PpapiPluginMsg_FlashDeviceID_GetDeviceIDReply(contents));
148 }
149
150 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/pepper/pepper_flash_device_id_host.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698