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

Side by Side Diff: content/browser/download/byte_stream.cc

Issue 10535116: Submitting ByteStream chrome class for Google C++ Readability Review. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
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 #include "content/browser/download/byte_stream.h" 5 #include "content/browser/download/byte_stream.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 15 matching lines...) Expand all
26 class ByteStreamReaderImpl; 26 class ByteStreamReaderImpl;
27 27
28 // A poor man's weak pointer; a RefCountedThreadSafe boolean that can be 28 // A poor man's weak pointer; a RefCountedThreadSafe boolean that can be
29 // cleared in an object destructor and accessed to check for object 29 // cleared in an object destructor and accessed to check for object
30 // existence. We can't use weak pointers because they're tightly tied to 30 // existence. We can't use weak pointers because they're tightly tied to
31 // threads rather than task runners. 31 // threads rather than task runners.
32 // TODO(rdsmith): A better solution would be extending weak pointers 32 // TODO(rdsmith): A better solution would be extending weak pointers
33 // to support SequencedTaskRunners. 33 // to support SequencedTaskRunners.
34 struct LifetimeFlag : public base::RefCountedThreadSafe<LifetimeFlag> { 34 struct LifetimeFlag : public base::RefCountedThreadSafe<LifetimeFlag> {
35 public: 35 public:
36 LifetimeFlag() : is_alive_(true) { } 36 LifetimeFlag() : is_alive_(true) { }
erikmc 2012/06/18 19:25:44 Structs have different naming rules for data membe
Randy Smith (Not in Mondays) 2012/06/18 20:38:24 Done.
37 bool is_alive_; 37 bool is_alive_;
38 38
39 protected: 39 protected:
40 friend class base::RefCountedThreadSafe<LifetimeFlag>; 40 friend class base::RefCountedThreadSafe<LifetimeFlag>;
41 virtual ~LifetimeFlag() { } 41 virtual ~LifetimeFlag() { }
42 42
43 private: 43 private:
44 DISALLOW_COPY_AND_ASSIGN(LifetimeFlag); 44 DISALLOW_COPY_AND_ASSIGN(LifetimeFlag);
45 }; 45 };
46 46
47 // For both ByteStreamWriterImpl and ByteStreamReaderImpl, Construction and 47 // For both ByteStreamWriterImpl and ByteStreamReaderImpl, Construction and
48 // SetPeer may happen anywhere; all other operations on each class must 48 // SetPeer may happen anywhere; all other operations on each class must
49 // happen in the context of their SequencedTaskRunner. 49 // happen in the context of their SequencedTaskRunner.
50 class ByteStreamWriterImpl : public content::ByteStreamWriter { 50 class ByteStreamWriterImpl : public content::ByteStreamWriter {
51 public: 51 public:
52 ByteStreamWriterImpl(scoped_refptr<base::SequencedTaskRunner> task_runner, 52 ByteStreamWriterImpl(scoped_refptr<base::SequencedTaskRunner> task_runner,
erikmc 2012/06/18 19:25:44 align inputs here
Randy Smith (Not in Mondays) 2012/06/18 20:38:24 Huh. Wonder how I managed that. Done.
53 scoped_refptr<LifetimeFlag> lifetime_flag, 53 scoped_refptr<LifetimeFlag> lifetime_flag,
54 size_t buffer_size); 54 size_t buffer_size);
55 virtual ~ByteStreamWriterImpl(); 55 virtual ~ByteStreamWriterImpl();
56 56
57 // Must be called before any operations are performed. 57 // Must be called before any operations are performed.
58 void SetPeer(ByteStreamReaderImpl* peer, 58 void SetPeer(ByteStreamReaderImpl* peer,
59 scoped_refptr<base::SequencedTaskRunner> peer_task_runner, 59 scoped_refptr<base::SequencedTaskRunner> peer_task_runner,
60 scoped_refptr<LifetimeFlag> peer_lifetime_flag); 60 scoped_refptr<LifetimeFlag> peer_lifetime_flag);
61 61
62 // Overridden from ByteStreamWriter. 62 // Overridden from ByteStreamWriter.
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 ByteStreamReaderImpl* out = new ByteStreamReaderImpl( 431 ByteStreamReaderImpl* out = new ByteStreamReaderImpl(
432 output_task_runner, output_flag, buffer_size); 432 output_task_runner, output_flag, buffer_size);
433 433
434 in->SetPeer(out, output_task_runner, output_flag); 434 in->SetPeer(out, output_task_runner, output_flag);
435 out->SetPeer(in, input_task_runner, input_flag); 435 out->SetPeer(in, input_task_runner, input_flag);
436 input->reset(in); 436 input->reset(in);
437 output->reset(out); 437 output->reset(out);
438 } 438 }
439 439
440 } // namespace content 440 } // namespace content
441
erikmc 2012/06/18 19:25:44 Please remove empty line 441.
Randy Smith (Not in Mondays) 2012/06/18 20:38:24 Yep--this was to get Rietveld to "take" the patch.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698