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

Side by Side Diff: components/sync_driver/sync_stopped_reporter.h

Issue 2203673002: [Sync] Move //components/sync_driver to //components/sync/driver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sd-a
Patch Set: Full change rebased on static lib. Created 4 years, 4 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
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 COMPONENTS_SYNC_DRIVER_SYNC_STOPPED_REPORTER_H_
6 #define COMPONENTS_SYNC_DRIVER_SYNC_STOPPED_REPORTER_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/timer/timer.h"
14 #include "net/url_request/url_fetcher.h"
15 #include "net/url_request/url_fetcher_delegate.h"
16 #include "net/url_request/url_request_context_getter.h"
17 #include "url/gurl.h"
18
19 namespace browser_sync {
20
21 // Manages informing the sync server that sync has been disabled.
22 // An implementation of URLFetcherDelegate was needed in order to
23 // clean up the fetcher_ pointer when the request completes.
24 class SyncStoppedReporter : public net::URLFetcherDelegate {
25 public:
26 enum Result {
27 RESULT_SUCCESS,
28 RESULT_ERROR,
29 RESULT_TIMEOUT
30 };
31
32 typedef base::Callback<void(const Result&)> ResultCallback;
33
34 SyncStoppedReporter(const GURL& sync_service_url,
35 const std::string& user_agent,
36 const scoped_refptr<net::URLRequestContextGetter>& request_context,
37 const ResultCallback& callback);
38 ~SyncStoppedReporter() override;
39
40 // Inform the sync server that sync was stopped on this device.
41 // |access_token|, |cache_guid|, and |birthday| must not be empty.
42 void ReportSyncStopped(const std::string& access_token,
43 const std::string& cache_guid,
44 const std::string& birthday);
45
46 // net::URLFetcherDelegate implementation.
47 void OnURLFetchComplete(const net::URLFetcher* source) override;
48
49 // Override the timer's task runner so it can be triggered in tests.
50 void SetTimerTaskRunnerForTest(
51 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
52
53 private:
54 // Convert the base sync URL into the sync event URL.
55 static GURL GetSyncEventURL(const GURL& sync_service_url);
56
57 // Callback for a request timing out.
58 void OnTimeout();
59
60 // Handles timing out requests.
61 base::OneShotTimer timer_;
62
63 // The URL for the sync server's event RPC.
64 const GURL sync_event_url_;
65
66 // The user agent for the browser.
67 const std::string user_agent_;
68
69 // Stored to simplify the API; needed for URLFetcher::Create().
70 scoped_refptr<net::URLRequestContextGetter> request_context_;
71
72 // The current URLFetcher. Null unless a request is in progress.
73 std::unique_ptr<net::URLFetcher> fetcher_;
74
75 // A callback for request completion or timeout.
76 ResultCallback callback_;
77
78 DISALLOW_COPY_AND_ASSIGN(SyncStoppedReporter);
79 };
80
81 } // namespace browser_sync
82
83 #endif // COMPONENTS_SYNC_DRIVER_SYNC_STOPPED_REPORTER_H_
OLDNEW
« no previous file with comments | « components/sync_driver/sync_service_utils.cc ('k') | components/sync_driver/sync_stopped_reporter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698