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

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

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 #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
45 // Schedules the request operation. The host will be called back with
46 // GotDRMContents. On failure, the contents will be empty.
47 void Start(content::BrowserPpapiHost* browser_host);
48
49 private:
50 friend struct content::BrowserThread::DeleteOnThread<
51 content::BrowserThread::IO>;
52 friend class base::DeleteHelper<Fetcher>;
53
54 ~Fetcher();
55
56 // Called on the UI thread to get the file path corresponding to the
57 // given render view. It will schedule the resulting file to be read on the
58 // file thread. On error, it will pass the empty path to the file thread.
59 void GetFilePathOnUIThread(int render_process_id,
60 int render_view_id);
61
62 // Called on the file thread to read the contents of the file and to
63 // forward it to the IO thread. The path will be empty on error (in
64 // which case it will forward the empty string to the IO thread).
65 void ReadDRMFileOnFileThread(const FilePath& path);
66
67 // Called on the IO thread to call back into the device ID host with the
68 // file contents, or the empty string on failure.
69 void ReplyOnIOThread(const std::string& contents);
70
71 // Access only on IO thread (this class is destroyed on the IO thread
72 // to ensure that this is deleted properly, since weak ptrs aren't
73 // threadsafe).
74 base::WeakPtr<PepperFlashDeviceIDHost> host_;
75
76 DISALLOW_COPY_AND_ASSIGN(Fetcher);
77 };
78 friend class Fetcher;
79
80 // IPC message handler.
81 int32_t OnHostMsgGetDeviceID(const ppapi::host::HostMessageContext* context);
82
83 // Called by the fetcher when the DRM ID was retrieved, or the empty string
84 // on error.
85 void GotDRMContents(const std::string& contents);
86
87 base::WeakPtrFactory<PepperFlashDeviceIDHost> factory_;
88
89 content::BrowserPpapiHost* browser_ppapi_host_;
90
91 // When a request is pending, the fetcher will be non-null, and the reply
92 // params will have the appropriate routing info set for the reply.
93 scoped_refptr<Fetcher> fetcher_;
94 ppapi::proxy::ResourceMessageReplyParams reply_params_;
95
96 DISALLOW_COPY_AND_ASSIGN(PepperFlashDeviceIDHost);
97 };
98
99 } // namespace chrome
100
101 #endif // CHROME_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FLASH_DEVICE_ID_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698