OLD | NEW |
---|---|
(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_RENDERER_HOST_PEPPER_PEPPER_FLASH_DEVICE_ID_HOST_H_ | |
6 #define CHROME_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FLASH_DEVICE_ID_HOST_H_ | |
7 | |
8 #include "base/memory/weak_ptr.h" | |
9 #include "content/public/browser/browser_thread.h" | |
10 #include "ppapi/host/resource_host.h" | |
11 #include "ppapi/proxy/resource_message_params.h" | |
12 | |
13 class FilePath; | |
14 | |
15 namespace content { | |
16 class BrowserPpapiHost; | |
17 } | |
18 | |
19 namespace chrome { | |
20 | |
21 class PepperFlashDeviceIDHost : public ppapi::host::ResourceHost { | |
22 public: | |
23 PepperFlashDeviceIDHost(content::BrowserPpapiHost* host, | |
24 PP_Instance instance, | |
25 PP_Resource resource); | |
26 virtual ~PepperFlashDeviceIDHost(); | |
27 | |
28 // ResourceHost override. | |
29 virtual int32_t OnResourceMessageReceived( | |
30 const IPC::Message& msg, | |
31 ppapi::host::HostMessageContext* context) OVERRIDE; | |
32 | |
33 private: | |
34 // Helper class to manage the unfortunate number of thread transitions | |
35 // required for this operation. We must first get the profile info from the | |
36 // UI thread, and then actually read the file from the FILE thread before | |
37 // returning to the IO thread to forward the result to the plugin. | |
38 class Fetcher | |
39 : public base::RefCountedThreadSafe< | |
40 Fetcher, | |
41 content::BrowserThread::DeleteOnIOThread> { | |
42 public: | |
43 explicit Fetcher(const base::WeakPtr<PepperFlashDeviceIDHost>& host); | |
44 ~Fetcher(); | |
45 | |
46 // Schedules the request operation. The host will be called back with | |
47 // GotDRMContents. On failure, the contents will be empty. | |
48 void Start(content::BrowserPpapiHost* browser_host); | |
49 | |
50 private: | |
51 // Called on the UI thread to get the file path corresponding to the | |
52 // given render view. It will schedule the resulting file to be read on the | |
53 // file thread. On error, it will pass the empty path to the file thread. | |
54 void GetFilePathOnUIThread(int render_process_id, | |
55 int render_view_id); | |
56 | |
57 // Called on the file thread to read the contents of the file and to | |
58 // forward it to the IO thread. The path will be empty on error (in | |
59 // which case it will forward the empty string to the IO thread). | |
60 void ReadDRMFileOnFileThread(const FilePath& path); | |
61 | |
62 // Called on the IO thread to call back into the device ID host with the | |
63 // file contents, or the empty string on failure. | |
64 void ReplyOnIOThread(const std::string& contents); | |
65 | |
66 // Access only on IO thread (this class is destroyed on the IO thread | |
yzshen1
2012/09/11 00:53:17
1. Access -> Accessed
2. Unbalanced '('
| |
67 // to ensure that this is deleted properly, since weak ptrs aren't | |
68 // threadsafe. | |
69 base::WeakPtr<PepperFlashDeviceIDHost> host_; | |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(Fetcher); | |
72 }; | |
73 friend class Fetcher; | |
74 | |
75 // IPC message handler. | |
76 int32_t OnHostMsgGetDeviceID(const ppapi::host::HostMessageContext* context); | |
77 | |
78 // Called by the fetcher when the DRM ID was retrieved, or the empty string | |
79 // on error. | |
80 void GotDRMContents(const std::string& contents); | |
81 | |
82 base::WeakPtrFactory<PepperFlashDeviceIDHost> factory_; | |
83 | |
84 content::BrowserPpapiHost* browser_ppapi_host_; | |
85 | |
86 // When a request is pending, the fetcher will be non-null, and the reply | |
87 // params will have the appropriate routing info set for the reply. | |
88 scoped_refptr<Fetcher> fetcher_; | |
89 ppapi::proxy::ResourceMessageReplyParams reply_params_; | |
90 | |
91 DISALLOW_COPY_AND_ASSIGN(PepperFlashDeviceIDHost); | |
92 }; | |
93 | |
94 } // namespace chrome | |
95 | |
96 #endif // CHROME_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FLASH_DEVICE_ID_HOST_H_ | |
OLD | NEW |