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

Side by Side Diff: chrome/browser/data_usage/tab_id_provider.h

Issue 1421983002: Include tab IDs when reporting data use accounting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@data_use_scoped_vector
Patch Set: Moved tab ID determination logic into data_usage codebase. Created 5 years, 1 month 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 (c) 2015 The Chromium Authors. All rights reserved.
bengr 2015/11/05 00:00:38 "(c)" -> ""
sclittle 2015/11/05 01:22:48 Done.
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 CHROME_BROWSER_DATA_USAGE_TAB_ID_PROVIDER_H_
6 #define CHROME_BROWSER_DATA_USAGE_TAB_ID_PROVIDER_H_
7
8 #include <stdint.h>
9
10 #include "base/callback_forward.h"
11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/supports_user_data.h"
14 #include "base/threading/thread_checker.h"
15
16 namespace base {
17 class TaskRunner;
18 }
19
20 namespace tracked_objects {
21 class Location;
22 }
23
24 namespace chrome_browser_data_usage {
25
26 // Object that can be attached to a URLRequest to provide the tab ID of that
27 // URLRequest to callbacks that want them. Callbacks are either run immediately
28 // if the tab ID is already available, or queued to be run later once the tab ID
29 // becomes available.
30 class TabIdProvider : public base::SupportsUserData::Data {
31 public:
32 // Constructs a tab ID provider, posting the |tab_id_getter| task onto
33 // |task_runner|.
34 TabIdProvider(base::TaskRunner* task_runner,
35 const tracked_objects::Location& from_here,
36 const base::Callback<int32_t(void)>& tab_id_getter);
37
38 ~TabIdProvider() override;
39
40 // Calls |callback| with the tab ID, either immediately if it's already
41 // available, or later once it becomes available.
42 void ProvideTabId(const base::Callback<void(int32_t)>& callback);
43
44 base::WeakPtr<TabIdProvider> GetWeakPtr();
45
46 static const void* kUserDataKey;
47
48 private:
49 class CallbackRunner;
50
51 // Called when the |tab_id| is ready.
52 void OnTabIdReady(int32_t tab_id);
53
54 base::ThreadChecker thread_checker_;
55 bool is_tab_id_ready_;
bengr 2015/11/05 00:00:38 Why do you need both a tab_id and this? Couldn't i
sclittle 2015/11/05 01:22:48 -1 is special, it means that no tab ID was found,
56 int32_t tab_id_;
57 base::WeakPtr<CallbackRunner> weak_callback_runner_;
58 base::WeakPtrFactory<TabIdProvider> weak_ptr_factory_;
59
60 DISALLOW_COPY_AND_ASSIGN(TabIdProvider);
61 };
62
63 } // namespace chrome_browser_data_usage
64
65 #endif // CHROME_BROWSER_DATA_USAGE_TAB_ID_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698