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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/job_event_router.h

Issue 1023923002: Files.app: Add JobEventRouter class that handles Job related events of Files.app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/file_manager/job_event_router.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_JOB_EVENT_ROUTER_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_JOB_EVENT_ROUTER_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/threading/thread_checker.h"
14 #include "base/time/time.h"
15 #include "base/values.h"
16 #include "chrome/browser/chromeos/drive/job_list.h"
17 #include "chrome/common/extensions/api/file_manager_private.h"
18 #include "url/gurl.h"
19
20 namespace file_manager {
21
22 // Files.app's event router handling job related events.
23 class JobEventRouter : public drive::JobListObserver {
24 public:
25 explicit JobEventRouter(const base::TimeDelta& event_delay);
26 ~JobEventRouter() override;
27
28 // drive::JobListObserver overrides.
29 void OnJobAdded(const drive::JobInfo& job_info) override;
30 void OnJobUpdated(const drive::JobInfo& job_info) override;
31 void OnJobDone(const drive::JobInfo& job_info,
32 drive::FileError error) override;
33
34 protected:
35 // Helper method to convert drive path to file system URL.
36 virtual GURL ConvertDrivePathToFileSystemUrl(const base::FilePath& path,
37 const std::string& id) const = 0;
38
39 // Helper method to dispatch events.
40 virtual void BroadcastEvent(const std::string& event_name,
41 scoped_ptr<base::ListValue> event_args) = 0;
42
43 private:
44 // Request sending transfer event with |job_info| and |state|.
45 // If |immediate| is true, the event will be dispatched synchronously.
46 // Otherwise, the event is throttled, or may be skipped.
47 void ScheduleDriveFileTransferEvent(
48 const drive::JobInfo& job_info,
49 extensions::api::file_manager_private::TransferState state,
50 bool immediate);
51
52 // Send transfer event requested by ScheduleDriveFileTransferEvent at last.
53 void SendDriveFileTransferEvent();
54
55 // Update |num_completed_bytes_| and |num_total_bytes_| depends on |job|.
56 void UpdateBytes(const drive::JobInfo& job_info);
57
58 // Delay time before sending progress events.
59 base::TimeDelta event_delay_;
60
61 // Set of job that are in the job schedular.
62 std::map<drive::JobID, linked_ptr<drive::JobInfo>> drive_jobs_;
63
64 // Pending transfer event. |ScheduleDriveFileTransferEvent| registers timeout
65 // callback to dispatch this.
66 scoped_ptr<extensions::api::file_manager_private::FileTransferStatus>
67 pending_event_;
68
69 // Computed bytes of tasks that have been processed. Once it completes all
70 // tasks, it clears the variable.
71 int64 num_completed_bytes_;
72
73 // Total bytes of tasks that have been processed. Once it completes all tasks,
74 // it clears the variable.
75 int64 num_total_bytes_;
76
77 // Thread checker.
78 base::ThreadChecker thread_checker_;
79
80 // Note: This should remain the last member so it'll be destroyed and
81 // invalidate the weak pointers before any other members are destroyed.
82 base::WeakPtrFactory<JobEventRouter> weak_factory_;
83
84 DISALLOW_COPY_AND_ASSIGN(JobEventRouter);
85 };
86
87 } // namespace file_manager
88
89 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_JOB_EVENT_ROUTER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/file_manager/job_event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698