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

Side by Side Diff: chrome/browser/ui/tabs/tab_utils.h

Issue 1233263002: Clean up error handling logic for extension tab muting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change WARNs to ERRORs, more variable renamings Created 5 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_UI_TABS_TAB_UTILS_H_ 5 #ifndef CHROME_BROWSER_UI_TABS_TAB_UTILS_H_
6 #define CHROME_BROWSER_UI_TABS_TAB_UTILS_H_ 6 #define CHROME_BROWSER_UI_TABS_TAB_UTILS_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10 #include "base/containers/hash_tables.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "content/public/browser/web_contents_user_data.h" 13 #include "content/public/browser/web_contents_user_data.h"
14 14
15 class TabStripModel; 15 class TabStripModel;
16 16
17 namespace content { 17 namespace content {
18 class WebContents; 18 class WebContents;
19 } // namespace content 19 } // namespace content
20 20
21 namespace gfx { 21 namespace gfx {
22 class Animation; 22 class Animation;
23 class Image; 23 class Image;
24 } // namespace gfx 24 } // namespace gfx
25 25
26 // Media state for a tab. In reality, more than one of these may apply. See 26 // Media state for a tab. In reality, more than one of these may apply. See
27 // comments for GetTabMediaStateForContents() below. 27 // comments for GetTabMediaStateForContents() below.
28 enum TabMediaState { 28 enum TabMediaState {
29 TAB_MEDIA_STATE_NONE, 29 TAB_MEDIA_STATE_NONE,
30 TAB_MEDIA_STATE_RECORDING, // Audio/Video being recorded, consumed by tab. 30 TAB_MEDIA_STATE_RECORDING, // Audio/Video being recorded, consumed by tab.
31 TAB_MEDIA_STATE_CAPTURING, // Tab contents being captured. 31 TAB_MEDIA_STATE_CAPTURING, // Tab contents being captured.
32 TAB_MEDIA_STATE_AUDIO_PLAYING, // Audible audio is playing from the tab. 32 TAB_MEDIA_STATE_AUDIO_PLAYING, // Audible audio is playing from the tab.
33 TAB_MEDIA_STATE_AUDIO_MUTING, // Tab audio is being muted. 33 TAB_MEDIA_STATE_AUDIO_MUTING, // Tab audio is being muted.
34 }; 34 };
35 35
36 enum TabMutedResult {
37 TAB_MUTED_RESULT_NONE,
miu 2015/07/15 01:45:55 Don't need TAB_MUTED_RESULT_NONE. Also, per my la
Jared Sohn 2015/07/15 02:33:34 The intention was to set a default enum value, but
38 TAB_MUTED_RESULT_SUCCESS,
39 TAB_MUTED_RESULT_FAIL_NOT_ENABLED,
40 TAB_MUTED_RESULT_FAIL_NO_CONTENTS,
41 TAB_MUTED_RESULT_FAIL_TABCAPTURE,
42 TAB_MUTED_RESULT_FAIL_RATE_LIMITED,
43 };
44
36 namespace chrome { 45 namespace chrome {
37 46
38 // String to indicate reason for muted state change (user, capture, extension 47 // String to indicate reason for muted state change (user, capture, extension
39 // id, or empty string) 48 // id, or empty string)
40 extern const char kMutedToggleCauseUser[]; 49 extern const char kMutedToggleCauseUser[];
41 extern const char kMutedToggleCauseCapture[]; 50 extern const char kMutedToggleCauseCapture[];
42 51
52 // Constants for rate limiting mute updating by extensions
53 extern const base::TimeDelta kMuteTokenBucketCost =
miu 2015/07/15 01:45:56 Chromium requirement: Global constants have to be
Jared Sohn 2015/07/15 02:33:34 Will make this change.
54 base::TimeDelta::FromSeconds(15);
55 extern const base::TimeDelta kMuteTokenBucketCapacity =
56 3 * kMuteTokenBucketCost;
57
58 // Token buckets used to rate limit mute updating by extensions
59 struct MuteTokenBucketInfo {
60 base::TimeDelta token_bucket;
61 base::TimeTicks last_attempt;
62 MuteTokenBucketInfo() {
63 token_bucket = kMuteTokenBucketCapacity;
64 last_attempt = base::TimeTicks::Now();
65 }
66 };
67 typedef base::hash_map<std::string, linked_ptr<MuteTokenBucketInfo>>
68 MuteTokenBucketInfoMap;
69
43 // Logic to determine which components (i.e., close button, favicon, and media 70 // Logic to determine which components (i.e., close button, favicon, and media
44 // indicator) of a tab should be shown, given current state. |capacity| 71 // indicator) of a tab should be shown, given current state. |capacity|
45 // specifies how many components can be shown, given available tab width. 72 // specifies how many components can be shown, given available tab width.
46 // 73 //
47 // Precedence rules for deciding what to show when capacity is insufficient to 74 // Precedence rules for deciding what to show when capacity is insufficient to
48 // show everything: 75 // show everything:
49 // 76 //
50 // Active tab: Always show the close button, then the media indicator, then 77 // Active tab: Always show the close button, then the media indicator, then
51 // the favicon. 78 // the favicon.
52 // Inactive tab: Media indicator, then the favicon, then the close button. 79 // Inactive tab: Media indicator, then the favicon, then the close button.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 base::string16 AssembleTabTooltipText(const base::string16& title, 124 base::string16 AssembleTabTooltipText(const base::string16& title,
98 TabMediaState media_state); 125 TabMediaState media_state);
99 126
100 // Returns true if the experimental tab audio mute feature is enabled. 127 // Returns true if the experimental tab audio mute feature is enabled.
101 bool IsTabAudioMutingFeatureEnabled(); 128 bool IsTabAudioMutingFeatureEnabled();
102 129
103 // Returns true if audio mute can be activated/deactivated for the given 130 // Returns true if audio mute can be activated/deactivated for the given
104 // |contents|. 131 // |contents|.
105 bool CanToggleAudioMute(content::WebContents* contents); 132 bool CanToggleAudioMute(content::WebContents* contents);
106 133
134 // Returns true if extension-driven muting is rate limited for a tab
135 bool IsTabAudioMutedRateLimited(content::WebContents* contents,
136 const std::string& cause);
137
107 // Indicates whether all audio output from |contents| is muted. 138 // Indicates whether all audio output from |contents| is muted.
108 bool IsTabAudioMuted(content::WebContents* contents); 139 bool IsTabAudioMuted(content::WebContents* contents);
109 140
110 // Sets whether all audio output from |contents| is muted. 141 // Sets whether all audio output from |contents| is muted.
111 // Cause is extensionid, kMutedToggleCause constant, or empty string 142 // Cause is extensionid, kMutedToggleCause constant, or empty string
112 void SetTabAudioMuted(content::WebContents* contents, 143 TabMutedResult SetTabAudioMuted(content::WebContents* contents,
113 bool mute, 144 bool mute,
114 const std::string& cause); 145 const std::string& cause);
115 146
116 // Get cause of mute (extensionid, kMutedToggleCause constant, or empty string) 147 // Get cause of mute (extensionid, kMutedToggleCause constant, or empty string)
117 const std::string& GetTabAudioMutedCause(content::WebContents* contents); 148 const std::string& GetTabAudioMutedCause(content::WebContents* contents);
118 149
119 // Returns true if the tabs at the |indices| in |tab_strip| are all muted. 150 // Returns true if the tabs at the |indices| in |tab_strip| are all muted.
120 bool AreAllTabsMuted(const TabStripModel& tab_strip, 151 bool AreAllTabsMuted(const TabStripModel& tab_strip,
121 const std::vector<int>& indices); 152 const std::vector<int>& indices);
122 153
123 } // namespace chrome 154 } // namespace chrome
124 155
125 #endif // CHROME_BROWSER_UI_TABS_TAB_UTILS_H_ 156 #endif // CHROME_BROWSER_UI_TABS_TAB_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698