[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / chrome / utility / media_galleries / ipc_data_source.h
blobdda9364be6924870583be1262fb0dd5ede2bb5cf
1 // Copyright 2014 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_UTILITY_MEDIA_GALLERIES_IPC_DATA_SOURCE_H_
6 #define CHROME_UTILITY_MEDIA_GALLERIES_IPC_DATA_SOURCE_H_
8 #include <map>
9 #include <string>
11 #include "base/memory/ref_counted.h"
12 #include "base/threading/thread_checker.h"
13 #include "chrome/utility/utility_message_handler.h"
14 #include "media/base/data_source.h"
16 namespace base {
17 class TaskRunner;
20 namespace metadata {
22 // Provides the metadata parser with bytes from the browser process via IPC.
23 // Class must be created and destroyed on the utility thread. Class may be used
24 // as a DataSource on a different thread. The utility thread must not be blocked
25 // for read operations to succeed.
26 class IPCDataSource: public media::DataSource,
27 public UtilityMessageHandler {
28 public:
29 // May only be called on the utility thread.
30 explicit IPCDataSource(int64 total_size);
31 ~IPCDataSource() override;
33 // Implementation of DataSource. These methods may be called on any single
34 // thread. First usage of these methods attaches a thread checker.
35 void Stop() override;
36 void Read(int64 position,
37 int size,
38 uint8* data,
39 const ReadCB& read_cb) override;
40 bool GetSize(int64* size_out) override;
41 bool IsStreaming() override;
42 void SetBitrate(int bitrate) override;
44 // Implementation of UtilityMessageHandler. May only be called on the utility
45 // thread.
46 bool OnMessageReceived(const IPC::Message& message) override;
48 private:
49 struct Request {
50 Request();
51 ~Request();
52 uint8* destination;
53 ReadCB callback;
56 void ReadOnUtilityThread(int64 position, int size, uint8* data,
57 const ReadCB& read_cb);
59 void OnRequestBlobBytesFinished(int64 request_id,
60 const std::string& bytes);
62 const int64 total_size_;
64 scoped_refptr<base::TaskRunner> utility_task_runner_;
65 std::map<int64, Request> pending_requests_;
66 int64 next_request_id_;
68 base::ThreadChecker utility_thread_checker_;
70 // Enforces that the DataSource methods are called on one other thread only.
71 base::ThreadChecker data_source_thread_checker_;
74 } // namespace metadata
76 #endif // CHROME_UTILITY_MEDIA_GALLERIES_IPC_DATA_SOURCE_H_