Chromium Code Reviews| Index: chrome/browser/ui/tabs/tab_utils.h |
| diff --git a/chrome/browser/ui/tabs/tab_utils.h b/chrome/browser/ui/tabs/tab_utils.h |
| index 2ca81514a81b2d0486e6534def812969cb610cd2..a6c217475f6ba70cf109400c9510ff61999525a1 100644 |
| --- a/chrome/browser/ui/tabs/tab_utils.h |
| +++ b/chrome/browser/ui/tabs/tab_utils.h |
| @@ -7,7 +7,7 @@ |
| #include <string> |
| #include <vector> |
| - |
| +#include "base/containers/hash_tables.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/strings/string16.h" |
| #include "content/public/browser/web_contents_user_data.h" |
| @@ -33,6 +33,15 @@ enum TabMediaState { |
| TAB_MEDIA_STATE_AUDIO_MUTING, // Tab audio is being muted. |
| }; |
| +enum TabMutedResult { |
| + 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
|
| + TAB_MUTED_RESULT_SUCCESS, |
| + TAB_MUTED_RESULT_FAIL_NOT_ENABLED, |
| + TAB_MUTED_RESULT_FAIL_NO_CONTENTS, |
| + TAB_MUTED_RESULT_FAIL_TABCAPTURE, |
| + TAB_MUTED_RESULT_FAIL_RATE_LIMITED, |
| +}; |
| + |
| namespace chrome { |
| // String to indicate reason for muted state change (user, capture, extension |
| @@ -40,6 +49,24 @@ namespace chrome { |
| extern const char kMutedToggleCauseUser[]; |
| extern const char kMutedToggleCauseCapture[]; |
| +// Constants for rate limiting mute updating by extensions |
| +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.
|
| + base::TimeDelta::FromSeconds(15); |
| +extern const base::TimeDelta kMuteTokenBucketCapacity = |
| + 3 * kMuteTokenBucketCost; |
| + |
| +// Token buckets used to rate limit mute updating by extensions |
| +struct MuteTokenBucketInfo { |
| + base::TimeDelta token_bucket; |
| + base::TimeTicks last_attempt; |
| + MuteTokenBucketInfo() { |
| + token_bucket = kMuteTokenBucketCapacity; |
| + last_attempt = base::TimeTicks::Now(); |
| + } |
| +}; |
| +typedef base::hash_map<std::string, linked_ptr<MuteTokenBucketInfo>> |
| + MuteTokenBucketInfoMap; |
| + |
| // Logic to determine which components (i.e., close button, favicon, and media |
| // indicator) of a tab should be shown, given current state. |capacity| |
| // specifies how many components can be shown, given available tab width. |
| @@ -104,14 +131,18 @@ bool IsTabAudioMutingFeatureEnabled(); |
| // |contents|. |
| bool CanToggleAudioMute(content::WebContents* contents); |
| +// Returns true if extension-driven muting is rate limited for a tab |
| +bool IsTabAudioMutedRateLimited(content::WebContents* contents, |
| + const std::string& cause); |
| + |
| // Indicates whether all audio output from |contents| is muted. |
| bool IsTabAudioMuted(content::WebContents* contents); |
| // Sets whether all audio output from |contents| is muted. |
| // Cause is extensionid, kMutedToggleCause constant, or empty string |
| -void SetTabAudioMuted(content::WebContents* contents, |
| - bool mute, |
| - const std::string& cause); |
| +TabMutedResult SetTabAudioMuted(content::WebContents* contents, |
| + bool mute, |
| + const std::string& cause); |
| // Get cause of mute (extensionid, kMutedToggleCause constant, or empty string) |
| const std::string& GetTabAudioMutedCause(content::WebContents* contents); |