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

Side by Side Diff: chrome/browser/media/router/discovery/dial/device_description_service.h

Issue 2701633002: [Media Router] Add DialMediaSinkService and DeviceDescriptionService (Closed)
Patch Set: resolve code review comments from Mark cont Created 3 years, 8 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 2017 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_MEDIA_ROUTER_DISCOVERY_DIAL_DEVICE_DESCRIPTION_SERVICE_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DEVICE_DESCRIPTION_SERVICE_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/callback.h"
12 #include "base/threading/thread_checker.h"
13 #include "chrome/browser/media/router/discovery/dial/dial_device_data.h"
14 #include "chrome/browser/media/router/discovery/dial/parsed_dial_device_descript ion.h"
15 #include "chrome/common/media_router/dial_device_description_parser.mojom.h"
16
17 namespace net {
18 class URLRequestContextGetter;
19 }
20
21 namespace media_router {
22
23 class DeviceDescriptionFetcher;
24
25 // Represents cached device description data parsed from device description xml.
26 struct CachedParsedDialDeviceDescription {
mark a. foltz 2017/04/12 00:17:17 Creating this as a private struct below, e.g. Devi
zhaobin 2017/04/18 06:58:26 Done.
27 CachedParsedDialDeviceDescription();
28 CachedParsedDialDeviceDescription(
29 const CachedParsedDialDeviceDescription& other);
30 ~CachedParsedDialDeviceDescription();
31
32 // The time the description was fetched, in ms after the epoch.
33 base::Time fetch_time_millis;
imcheng 2017/04/12 19:33:50 Omit the millis / ms part in the name / comments s
zhaobin 2017/04/18 06:58:27 Done.
34
35 // The expiration time from the cache, in ms after the epoch.
36 base::Time expire_time_millis;
37
38 // The version number.
39 base::Optional<int32_t> config_id;
mark a. foltz 2017/04/12 00:17:18 It might be simpler to provide a default of -1 vs.
zhaobin 2017/04/18 06:58:26 Done.
40
41 // Underlying device description data from xml
mark a. foltz 2017/04/12 00:17:18 s/xml/XML./
zhaobin 2017/04/18 06:58:26 Done.
42 ParsedDialDeviceDescription description_data;
43 };
44
45 class DeviceDescriptionService {
imcheng 2017/04/12 19:33:50 Please document threading assumptions when providi
zhaobin 2017/04/18 06:58:26 Done.
46 public:
47 // Called if parsing device description xml in utility process succeeds, and
mark a. foltz 2017/04/12 00:17:18 Nit: s/xml/XML/ throughout as it's an abbreviation
zhaobin 2017/04/18 06:58:26 Done.
48 // all fields are valid.
49 // |device_data|: The device to look up.
50 // |description_data|: Device description data from device description xml.
51 using DeviceDescriptionParseSuccessCallback =
52 base::Callback<void(const DialDeviceData& device_data,
53 const ParsedDialDeviceDescription& description_data)>;
54
55 // Called if parsing device description xml in utility process fails, or some
56 // parsed fields are missing or invalid.
57 using DeviceDescriptionParseErrorCallback =
58 base::Callback<void(const std::string& device_label,
imcheng 2017/04/12 19:33:50 Why does this only return the device label only vs
zhaobin 2017/04/18 06:58:26 Done.
59 const std::string& error_message)>;
60
61 DeviceDescriptionService(DeviceDescriptionParseSuccessCallback success_cb,
imcheng 2017/04/12 19:33:50 const ref for both args
zhaobin 2017/04/18 06:58:26 Done.
62 DeviceDescriptionParseErrorCallback error_cb);
63 virtual ~DeviceDescriptionService();
64
65 // For each device in |devices|, if there is a valid cache entry for it, call
66 // |success_cb_| with cached device description; otherwise start fetching
67 // device description xml and parsing xml in utility process. Call
68 // |success_cb_| if both fetching and parsing succeeds; otherwise call
69 // |error_cb_|.
70 virtual void GetDeviceDescriptions(
71 const std::vector<DialDeviceData>& devices,
72 net::URLRequestContextGetter* request_context);
mark a. foltz 2017/04/12 00:17:18 Document |request_context|
zhaobin 2017/04/18 06:58:26 Done.
73
74 private:
75 // Issues a HTTP GET request for the device description. No-op if there is
76 // already a pending request.
77 // |device_data|: The device to look up.
78 void FetchDeviceDescription(const DialDeviceData& device_data,
79 net::URLRequestContextGetter* request_context);
80
81 // Checks the cache for a valid device description. If the entry is found but
82 // is no longer valid, it is removed from the cache.
83 // |device_data|: The device to look up.
84 // |out_description|: Cached entry of parsed device description. Returns
85 // nullptr if cache entry does not exist or is not valid.
86 bool CheckAndUpdateCache(const DialDeviceData& device_data,
87 CachedParsedDialDeviceDescription* out_description);
88
89 // Invoked when SafeDialDeviceDescriptionParser finishes parsing device
90 // description xml.
91 // |device_data|: Device data initiating xml parsing in utility process.
92 // |app_url|: The app Url.
93 // |device_description_ptr|: Parsed devcie description from utility process.
mark a. foltz 2017/04/12 00:17:17 typo in device
zhaobin 2017/04/18 06:58:26 Done.
94 // Returns nullptr if parsing fails.
95 void OnParsedDeviceDescription(
96 const DialDeviceData& device_data,
97 const GURL& app_url,
98 chrome::mojom::DialDeviceDescriptionPtr device_description_ptr);
99
100 // Invoked when HTTP GET request finishes.
mark a. foltz 2017/04/12 00:17:18 Maybe this (and the following method) should be gr
zhaobin 2017/04/18 06:58:27 Done.
101 // |device_data|: Device data initiating the HTTP request.
102 // |description_data|: Response from HTTP request.
103 void OnDeviceDescriptionFetchComplete(
104 const DialDeviceData& device_data,
105 const DialDeviceDescriptionData& description_data);
106
107 // Invoked when HTTP GET request fails.
108 // |device_data|: Device data initiating the HTTP request.
109 void OnDeviceDescriptionFetchError(const DialDeviceData& device_data,
110 const std::string& error_message);
111
112 // Map of <device label, DeviceDescriptionFetcher>
113 std::map<std::string, std::unique_ptr<DeviceDescriptionFetcher>>
114 device_description_fetcher_map_;
115
116 // Map of <device label, CachedParsedDialDeviceDescription>
117 std::map<std::string, CachedParsedDialDeviceDescription> description_map_;
118
119 // See comments for DeviceDescriptionParseSuccessCallback.
120 DeviceDescriptionParseSuccessCallback success_cb_;
121
122 // See comments for DeviceDescriptionParseErrorCallback.
123 DeviceDescriptionParseErrorCallback error_cb_;
124
125 base::ThreadChecker thread_checker_;
126 };
127
128 } // namespace media_router
129
130 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DEVICE_DESCRIPTION_SERVICE _H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698