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

Side by Side Diff: chrome/utility/media_galleries/ipc_data_source.h

Issue 2667443002: Convert utility process ParseMediaMetadata blob reading IPC to mojo (Closed)
Patch Set: Remove the damn helper: call ReleaseProcessIfNeeded directly. Created 3 years, 10 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_UTILITY_MEDIA_GALLERIES_IPC_DATA_SOURCE_H_ 5 #ifndef CHROME_UTILITY_MEDIA_GALLERIES_IPC_DATA_SOURCE_H_
6 #define CHROME_UTILITY_MEDIA_GALLERIES_IPC_DATA_SOURCE_H_ 6 #define CHROME_UTILITY_MEDIA_GALLERIES_IPC_DATA_SOURCE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <string> 11 #include <string>
12 12
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "chrome/utility/utility_message_handler.h" 15 #include "chrome/common/extensions/media_parser.mojom.h"
16 #include "media/base/data_source.h" 16 #include "media/base/data_source.h"
17 17
18 namespace base { 18 namespace base {
19 class TaskRunner; 19 class TaskRunner;
20 } 20 }
21 21
22 namespace metadata { 22 namespace metadata {
23 23
24 // Provides the metadata parser with bytes from the browser process via IPC. 24 // Provides the metadata parser with blob data from the browser process. Class
25 // Class must be created and destroyed on the utility thread. Class may be used 25 // must be created and destroyed on the utility thread. Class may be used as a
26 // as a DataSource on a different thread. The utility thread must not be blocked 26 // DataSource on a different thread. The utility thread must not be blocked
27 // for read operations to succeed. 27 // for read operations to succeed.
28 class IPCDataSource: public media::DataSource, 28 class IPCDataSource : public media::DataSource {
29 public UtilityMessageHandler {
30 public: 29 public:
31 // May only be called on the utility thread. 30 // May only be called on the utility thread.
32 explicit IPCDataSource(int64_t total_size); 31 IPCDataSource(extensions::mojom::MediaDataSourcePtr media_data_source,
32 int64_t total_size);
33 ~IPCDataSource() override; 33 ~IPCDataSource() override;
34 34
35 // Implementation of DataSource. These methods may be called on any single 35 // media::DataSource implementation. The methods may be called on any single
36 // thread. First usage of these methods attaches a thread checker. 36 // thread. First usage of these methods attaches a thread checker.
37 void Stop() override; 37 void Stop() override;
38 void Abort() override; 38 void Abort() override;
39 void Read(int64_t position, 39 void Read(int64_t position,
40 int size, 40 int size,
41 uint8_t* data, 41 uint8_t* data,
42 const ReadCB& read_cb) override; 42 const ReadCB& read_cb) override;
43 bool GetSize(int64_t* size_out) override; 43 bool GetSize(int64_t* size_out) override;
44 bool IsStreaming() override; 44 bool IsStreaming() override;
45 void SetBitrate(int bitrate) override; 45 void SetBitrate(int bitrate) override;
46 46
47 // Implementation of UtilityMessageHandler. May only be called on the utility 47 private:
48 // thread. 48 struct Request;
49 bool OnMessageReceived(const IPC::Message& message) override;
50 49
51 private: 50 // Blob data read helpers: must be run on the utility thread.
52 struct Request { 51 void ReadBlob(int64_t position,
53 Request(); 52 int size,
54 Request(const Request& other); 53 uint8_t* data,
55 ~Request(); 54 const ReadCB& read_cb);
56 uint8_t* destination; 55 void ReadDone(int64_t request_id, const std::vector<uint8_t>& data);
57 ReadCB callback;
58 };
59 56
60 void ReadOnUtilityThread(int64_t position, 57 extensions::mojom::MediaDataSourcePtr media_data_source_;
61 int size,
62 uint8_t* data,
63 const ReadCB& read_cb);
64
65 void OnRequestBlobBytesFinished(int64_t request_id, const std::string& bytes);
66
67 const int64_t total_size_; 58 const int64_t total_size_;
68 59
69 scoped_refptr<base::TaskRunner> utility_task_runner_; 60 scoped_refptr<base::TaskRunner> utility_task_runner_;
70 std::map<int64_t, Request> pending_requests_; 61 std::map<int64_t, Request> pending_requests_;
71 int64_t next_request_id_; 62 int64_t next_request_id_;
72 63
73 base::ThreadChecker utility_thread_checker_; 64 base::ThreadChecker utility_thread_checker_;
74 65
75 // Enforces that the DataSource methods are called on one other thread only. 66 // Enforces that the DataSource methods are called on one other thread only.
76 base::ThreadChecker data_source_thread_checker_; 67 base::ThreadChecker data_source_thread_checker_;
77 }; 68 };
78 69
79 } // namespace metadata 70 } // namespace metadata
80 71
81 #endif // CHROME_UTILITY_MEDIA_GALLERIES_IPC_DATA_SOURCE_H_ 72 #endif // CHROME_UTILITY_MEDIA_GALLERIES_IPC_DATA_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698