summaryrefslogtreecommitdiffstats
path: root/content/browser/devtools/protocol/system_info_handler.h
blob: 485bdab4dd70b4954d43ecfc4c66d9143c864f81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SYSTEM_INFO_HANDLER_H_
#define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SYSTEM_INFO_HANDLER_H_

#include <set>

#include "content/browser/devtools/protocol/devtools_protocol_handler.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/gpu_data_manager_observer.h"

namespace content {
namespace devtools {
namespace system_info {

class SystemInfoHandler {
 public:
  using Response = DevToolsProtocolClient::Response;

  SystemInfoHandler();
  ~SystemInfoHandler();

  void SetClient(scoped_ptr<Client> client);

  Response GetInfo(DevToolsCommandId command_id);

 private:
  friend class SystemInfoHandlerGpuObserver;

  void SendGetInfoResponse(DevToolsCommandId command_id);

  // Bookkeeping for the active GpuObservers.
  void AddActiveObserverId(int observer_id);
  bool RemoveActiveObserverId(int observer_id);
  void ObserverWatchdogCallback(int observer_id, DevToolsCommandId command_id);

  // For robustness, we have to guarantee a response to getInfo requests.
  // It's very unlikely that the requests will time out. The
  // GpuDataManager's threading model is not well defined (see comments in
  // gpu_data_manager_impl.h) and it is very difficult to correctly clean
  // up its observers. For the moment, especially since these classes are
  // only used in tests, we leak a little bit of memory if we don't get a
  // callback from the GpuDataManager in time.
  mutable base::Lock lock_;
  std::set<int> active_observers_;

  scoped_ptr<Client> client_;
  base::WeakPtrFactory<SystemInfoHandler> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(SystemInfoHandler);
};

}  // namespace system_info
}  // namespace devtools
}  // namespace content

#endif  // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SYSTEM_INFO_HANDLER_H_