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

Side by Side Diff: extensions/browser/api/cast_channel/cast_channel_service.h

Issue 2891023002: [cast_channel] Make CastSocket not inherit from ApiResource (Closed)
Patch Set: Created 3 years, 7 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 EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_
6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_
7
8 #include <map>
9 #include <memory>
10
11 #include "base/macros.h"
12 #include "base/threading/thread_checker.h"
13 #include "components/keyed_service/core/keyed_service.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "extensions/browser/api/cast_channel/cast_socket.h"
16
17 namespace extensions {
18 namespace api {
19 namespace cast_channel {
20
21 // This class manages cast sockets created by CastChannelAPI.
mark a. foltz 2017/05/18 18:02:26 Does this comment belong with CastChannelService?
zhaobin 2017/05/24 01:51:40 CastSocketRegistry does the actual management...Mo
22 // This class is not thread safe. All methods must be called from the IO thread.
23 class CastSocketData {
mark a. foltz 2017/05/18 18:02:26 Bikeshed: CastSocketRegistry?
zhaobin 2017/05/24 01:51:40 Done.
24 public:
25 CastSocketData();
26 ~CastSocketData();
27
28 // Adds |socket| to |manager_| and returns the new channel_id. Takes ownership
mark a. foltz 2017/05/18 18:02:26 Where is |manager_| declared?
zhaobin 2017/05/24 01:51:40 Done.
29 // of |socket|.
30 int AddSocket(CastSocket* socket);
mark a. foltz 2017/05/18 18:02:26 When ownership is transferred via parameter, it pr
zhaobin 2017/05/24 01:51:39 Done.
31
32 // Removes the CastSocket corresponding to |channel_id| from the resource
33 // manager.
34 void RemoveSocket(int channel_id);
mark a. foltz 2017/05/18 18:02:26 Nit: Consider returning std::unique_ptr<CastSocket
zhaobin 2017/05/24 01:51:39 Done.
35
36 // Returns the socket corresponding to |channel_id| if one exists, or null
37 // otherwise.
38 CastSocket* GetSocket(int channel_id) const;
39
40 private:
41 // The collection of CastSocket.
42 std::map<int, std::unique_ptr<CastSocket>> sockets_;
43
44 THREAD_CHECKER(thread_checker_);
45
46 DISALLOW_COPY_AND_ASSIGN(CastSocketData);
47 };
48
49 // This class associates underlying CastSocketData instance with BrowserContext
50 // and makes sure CastSocketData instance is created and destroyed on the IO
51 // thread.
52 class CastChannelService : public KeyedService {
mark a. foltz 2017/05/18 18:02:26 Bikeshed: Slight preference to name this class Cas
zhaobin 2017/05/24 01:51:40 It is a KeyedService, would like to keep Service..
mark a. foltz 2017/05/24 17:44:10 Yeah that makes sense.
53 public:
54 CastChannelService();
55 ~CastChannelService() override;
56
57 // Creates CastSocketData instance if none exists.
58 CastSocketData* GetOrCreateSocketData();
mark a. foltz 2017/05/18 18:02:26 What thread is expected to invoke this method?
zhaobin 2017/05/24 01:51:40 Done.
59
60 private:
61 std::unique_ptr<CastSocketData, content::BrowserThread::DeleteOnIOThread>
62 sockets_;
63
64 DISALLOW_COPY_AND_ASSIGN(CastChannelService);
65 };
66
67 } // namespace cast_channel
68 } // namespace api
69 } // namespace extensions
70
71 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698