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

Side by Side Diff: chrome/browser/chromeos/arc/arc_support_host.h

Issue 2380683008: Fix resource leak on extension window closing. (Closed)
Patch Set: Address comments. Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_
6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "chrome/browser/chromeos/arc/arc_auth_service.h" 9 #include "chrome/browser/chromeos/arc/arc_auth_service.h"
10 #include "components/prefs/pref_change_registrar.h" 10 #include "components/prefs/pref_change_registrar.h"
11 #include "extensions/browser/api/messaging/native_message_host.h" 11 #include "extensions/browser/api/messaging/native_message_host.h"
12 #include "ui/display/display_observer.h" 12 #include "ui/display/display_observer.h"
13 13
14 // Supports communication with Arc support dialog. 14 // Supports communication with Arc support dialog.
15 class ArcSupportHost : public extensions::NativeMessageHost, 15 class ArcSupportHost : public extensions::NativeMessageHost,
16 public arc::ArcAuthService::Observer, 16 public arc::ArcAuthService::Observer,
17 public display::DisplayObserver { 17 public display::DisplayObserver {
18 public: 18 public:
19 static const char kHostName[]; 19 static const char kHostName[];
20 static const char kHostAppId[]; 20 static const char kHostAppId[];
21 static const char kStorageId[]; 21 static const char kStorageId[];
22 static const char* const kHostOrigin[]; 22 static const char* const kHostOrigin[];
23 23
24 static std::unique_ptr<NativeMessageHost> Create(); 24 static std::unique_ptr<NativeMessageHost> Create();
25 25
26 ~ArcSupportHost() override; 26 ~ArcSupportHost() override;
27 27
28 // Requests to close the extension window.
29 void Close();
30
28 // Overrides NativeMessageHost: 31 // Overrides NativeMessageHost:
29 void Start(Client* client) override; 32 void Start(Client* client) override;
30 void OnMessage(const std::string& request_string) override; 33 void OnMessage(const std::string& request_string) override;
31 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const override; 34 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const override;
32 35
33 // Overrides arc::ArcAuthService::Observer: 36 // Overrides arc::ArcAuthService::Observer:
37 // TODO(hidehiko): Get rid of Observer interface.
34 void OnOptInUIClose() override; 38 void OnOptInUIClose() override;
35 void OnOptInUIShowPage(arc::ArcAuthService::UIPage page, 39 void OnOptInUIShowPage(arc::ArcAuthService::UIPage page,
36 const base::string16& status) override; 40 const base::string16& status) override;
37 41
38 // display::DisplayObserver: 42 // display::DisplayObserver:
39 void OnDisplayAdded(const display::Display& new_display) override; 43 void OnDisplayAdded(const display::Display& new_display) override;
40 void OnDisplayRemoved(const display::Display& old_display) override; 44 void OnDisplayRemoved(const display::Display& old_display) override;
41 void OnDisplayMetricsChanged(const display::Display& display, 45 void OnDisplayMetricsChanged(const display::Display& display,
42 uint32_t changed_metrics) override; 46 uint32_t changed_metrics) override;
43 47
44 private: 48 private:
45 ArcSupportHost(); 49 ArcSupportHost();
46 50
47 bool Initialize(); 51 bool Initialize();
48 void OnMetricsPreferenceChanged(); 52 void OnMetricsPreferenceChanged();
49 void OnBackupAndRestorePreferenceChanged(); 53 void OnBackupAndRestorePreferenceChanged();
50 void OnLocationServicePreferenceChanged(); 54 void OnLocationServicePreferenceChanged();
51 void SendMetricsMode(); 55 void SendMetricsMode();
52 void SendBackupAndRestoreMode(); 56 void SendBackupAndRestoreMode();
53 void SendLocationServicesMode(); 57 void SendLocationServicesMode();
54 void SendOptionMode(const std::string& action_name, 58 void SendOptionMode(const std::string& action_name,
55 const std::string& pref_name); 59 const std::string& pref_name);
56 void EnableMetrics(bool is_enabled); 60 void EnableMetrics(bool is_enabled);
57 void EnableBackupRestore(bool is_enabled); 61 void EnableBackupRestore(bool is_enabled);
58 void EnableLocationService(bool is_enabled); 62 void EnableLocationService(bool is_enabled);
59 63
60 // Unowned pointer. 64 // Unowned pointer.
61 Client* client_ = nullptr; 65 Client* client_ = nullptr;
62 66
67 // Keep if Close() is requested from the browser.
68 // TODO(hidehiko): Remove this. This is temporarily introduced for checking
69 // if ArcAuthService::CancelAuthCode() needs to be invoked or not.
70 // ArcAuthService should know its own state and the transition so moving to
71 // there should simplify the structure. However, it is blocked by the current
72 // dependency. For the clean up, more refactoring is needed, which can be
73 // bigger changes.
74 bool close_requested_ = false;
75
63 // Used to track metrics preference. 76 // Used to track metrics preference.
64 PrefChangeRegistrar pref_local_change_registrar_; 77 PrefChangeRegistrar pref_local_change_registrar_;
65 // Used to track backup&restore and location service preference. 78 // Used to track backup&restore and location service preference.
66 PrefChangeRegistrar pref_change_registrar_; 79 PrefChangeRegistrar pref_change_registrar_;
67 80
68 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost); 81 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost);
69 }; 82 };
70 83
71 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ 84 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.cc ('k') | chrome/browser/chromeos/arc/arc_support_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698