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.
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_
8 #include "base/memory/weak_ptr.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "ppapi/host/host_message_context.h"
11 #include "ppapi/host/resource_host.h"
12 #include "ppapi/proxy/resource_message_params.h"
19 class BrowserPpapiHost
;
24 class PepperFlashDeviceIDHost
: public ppapi::host::ResourceHost
{
26 PepperFlashDeviceIDHost(content::BrowserPpapiHost
* host
,
28 PP_Resource resource
);
29 virtual ~PepperFlashDeviceIDHost();
31 // ResourceHost override.
32 virtual int32_t OnResourceMessageReceived(
33 const IPC::Message
& msg
,
34 ppapi::host::HostMessageContext
* context
) OVERRIDE
;
37 // Helper class to manage the unfortunate number of thread transitions
38 // required for this operation. We must first get the profile info from the
39 // UI thread, and then actually read the file from the FILE thread before
40 // returning to the IO thread to forward the result to the plugin.
42 : public base::RefCountedThreadSafe
<
44 content::BrowserThread::DeleteOnIOThread
> {
46 explicit Fetcher(const base::WeakPtr
<PepperFlashDeviceIDHost
>& host
);
48 // Schedules the request operation. The host will be called back with
49 // GotDRMContents. On failure, the contents will be empty.
50 void Start(content::BrowserPpapiHost
* browser_host
);
53 friend struct content::BrowserThread::DeleteOnThread
<
54 content::BrowserThread::IO
>;
55 friend class base::DeleteHelper
<Fetcher
>;
59 // Called on the UI thread to get the file path corresponding to the
60 // given render view. It will schedule the resulting file to be read on the
61 // file thread. On error, it will pass the empty path to the file thread.
62 void GetFilePathOnUIThread(int render_process_id
,
65 // Called on the file thread to read the contents of the file and to
66 // forward it to the IO thread. The path will be empty on error (in
67 // which case it will forward the empty string to the IO thread).
68 void ReadDRMFileOnFileThread(const base::FilePath
& path
);
70 // Called on the IO thread to call back into the device ID host with the
71 // file contents, or the empty string on failure.
72 void ReplyOnIOThread(const std::string
& contents
);
74 // Access only on IO thread (this class is destroyed on the IO thread
75 // to ensure that this is deleted properly, since weak ptrs aren't
77 base::WeakPtr
<PepperFlashDeviceIDHost
> host_
;
79 DISALLOW_COPY_AND_ASSIGN(Fetcher
);
83 // IPC message handler.
84 int32_t OnHostMsgGetDeviceID(const ppapi::host::HostMessageContext
* context
);
86 // Called by the fetcher when the DRM ID was retrieved, or the empty string
88 void GotDRMContents(const std::string
& contents
);
90 base::WeakPtrFactory
<PepperFlashDeviceIDHost
> factory_
;
92 content::BrowserPpapiHost
* browser_ppapi_host_
;
94 // When a request is pending, the fetcher will be non-null, and the reply
95 // context will have the appropriate routing info set for the reply.
96 scoped_refptr
<Fetcher
> fetcher_
;
97 ppapi::host::ReplyMessageContext reply_context_
;
99 DISALLOW_COPY_AND_ASSIGN(PepperFlashDeviceIDHost
);
102 } // namespace chrome
104 #endif // CHROME_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FLASH_DEVICE_ID_HOST_H_